토니의 연습장
정렬 예제 본문
https://www.acmicpc.net/problem/1946
import sys
input = sys.stdin.readline # 입력 빠르게 받기 위한 세팅
T = int(input())
for _ in range(T):
N = int(input())
candidates = []
for _ in range(N):
s, m = map(int, input().split())
candidates.append((s,m))
# (s,m)
candidates.sort() # 첫 번째 인자 기준 먼저 정렬, 같을 경우 두 번째 인자 기준 정렬됨
# but 문제 조건상 동석차 없음
top_ranking = 1e9 # 현재까지 최고 순위 기록해두기 (낮을수록 높은 값)
count = 0 # 합격자 수
for i in range(N):
if candidates[i][1] < top_ranking: # 면접 점수 확인
count += 1
top_ranking = candidates[i][1]
else: # 하위 호환
pass
print(count)
https://www.acmicpc.net/problem/11728
import sys
import collections
input = sys.stdin.readline
N, M = map(int, input().split())
# A, B 모두 정렬되어 있는 가정
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
pos1 = 0
pos2 = 0
while pos1 < N and pos2 < M:
candidate1 = A[pos1]
candidate2 = B[pos2]
if candidate1 < candidate2:
C.append(candidate1)
pos1 += 1
else:
C.append(candidate2)
pos2 += 1
if pos1 != N: # A가 다 소진되지 않은 상황
C.extend(A[pos1:N])
if pos2 != M: # B가 다 소진되지 않은 상황
C.extend(B[pos2:M])
for i in C:
print(i, end=" ")
'Algorithm > Ch 2. 기초 알고리즘' 카테고리의 다른 글
그리디 알고리즘 예제 (0) | 2024.09.10 |
---|---|
투 포인터 예제 (0) | 2024.09.06 |
완전 탐색 예제 (0) | 2024.09.06 |
이분 탐색 예제 (2) | 2024.09.05 |