11728: 배열 합치기

# 배열 합치기
# 그냥 배열 합쳐서 sort - 1248ms

import sys

input = sys.stdin.readline
n, m = map(int, input().split())

# ??? 그냥 정렬해보자
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = a + b
c.sort()

for x in c:
  print(x, end=' ')
# 배열 합치기
# 투 포인터 - 1148ms

import sys

input = sys.stdin.readline
n, m = map(int, input().split())

a = list(input().split())
b = list(input().split())

ap, bp = 0, 0

while ap != n or bp != m:
  if ap == n:
    b_temp = b[bp:]
    print(" ".join(b_temp))
    break
  elif bp == m:
    a_temp = a[ap:]
    print(" ".join(a_temp))
    break
  elif int(a[ap]) < int(b[bp]):
    print(a[ap], end=' ')
    ap += 1
  elif int(a[ap]) >= int(b[bp]):
    print(b[bp], end=' ')
    bp += 1

21921: 블로그

원래

import sys

input = sys.stdin.readline

n, x = map(int, input().split())
hits = list(map(int, input().split()))

sum_max = 0
window_sum = sum(hits[:x])
sum_max_cnt = 0

for start in range(n-x+1):
  if sum_max < window_sum:
    sum_max = window_sum
    sum_max_cnt = 1
  elif sum_max == window_sum:
    sum_max_cnt += 1

  if start == n - x:  # start가 n-x면 마지막 윈도우이므로 다음 window_sum을 구하지 않음
    break
  window_sum += hits[start+x] - hits[start]

if sum_max == 0:
  print("SAD")
else:
  print(sum_max)
  print(sum_max_cnt)
# 블로그
# 슬라이딩 윈도우 - 172ms

import sys

input = sys.stdin.readline

n, x = map(int, input().split())
hits = list(map(int, input().split()))

window_sum = sum(hits[:x])
sum_max = window_sum
# window_sum = 0
sum_max_cnt = 0

for start in range(n-x): # 0 ~ n - x - 1
	window_sum += hits[start+x] - hits[start] # += hits[x] - hits[0]
  if sum_max < window_sum:
    sum_max = window_sum
    sum_max_cnt = 1
  elif sum_max == window_sum:
    sum_max_cnt += 1

if sum_max == 0:
  print("SAD")
else:
  print(sum_max)
  print(sum_max_cnt)

20922: 겹치는 건 싫어

# 겹치는 건 싫어 - 176ms
# <https://khu98.tistory.com/187>
import sys

input = sys.stdin.readline

n, k = map(int, input().split())
nums = list(map(int, input().split()))
counter = [0] * (max(nums) + 1)

s, e = 0, 0
max_length = 0
while e < n:
  if counter[nums[e]] < k:  # end가 가리키는 수의 개수 확인
    counter[nums[e]] += 1
    e += 1
  else:  # end가 가리키는 수의 개수가 k개 이상이면 
    counter[nums[s]] -= 1
    s += 1
  max_length = max(max_length, e - s)
print(max_length)