File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed
Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change 1- # N 입력 받기
2- n = int (input ())
1+ n , k = map (int , input ().split ()) # N과 K를 입력 받기
2+ a = list (map (int , input ().split ())) # 배열 A의 모든 원소를 입력받기
3+ b = list (map (int , input ().split ())) # 배열 B의 모든 원소를 입력받기
34
4- count = [0 ] * 10001
5- result = - 1 # 가장 많이 가지고 있는 신발 번호
6- max_value = 0 # 가장 많이 가지고 있는 신발 번호의 신발 개수
5+ a .sort () # 배열 A는 오름차순 정렬 수행
6+ b .sort (reverse = True ) # 배열 B는 내림차순 정렬 수행
77
8- for i in range (n ):
9- a = int (input ())
10- count [a ] += 1
11- if max_value < count [a ]:
12- max_value = count [a ]
13- result = a # 가장 많이 가지고 있는 신발 번호 기록
8+ # 첫 번째 인덱스부터 확인하며, 두 배열의 원소를 최대 K번 비교
9+ for i in range (k ):
10+ # A의 원소가 B의 원소보다 작은 경우
11+ if a [i ] < b [i ]:
12+ # 두 원소를 교체
13+ a [i ], b [i ] = b [i ], a [i ]
14+ else : # A의 원소가 B의 원소보다 크거나 같을 때, 반복문을 탈출
15+ break
1416
15- print (result )
17+ print (sum ( a )) # 배열 A의 모든 원소의 합을 출력
You can’t perform that action at this time.
0 commit comments