카테고리 없음
[문제 풀이] 11월 6일
스히
2023. 11. 6. 01:04
< 꿀 아르바이트 > -백준 12847
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
pays = list(map(int, input().split()))
profit = 0
for i in range(0, m):
profit += pays[i]
max_profit = profit
start = 0
end = m - 1
while end < n - 1:
end += 1
profit -= pays[start]
profit += pays[end]
max_profit = max(max_profit, profit)
start += 1
print(max_profit)
< 좋은 친구 > - 백준 3078
import sys
input = sys.stdin.readline
from collections import defaultdict
n, k = list(map(int, input().split()))
people = []
for _ in range(n):
people.append(len(input().strip()))
check = defaultdict(int)
count = 0
for i in range(n):
if i > k:
check[people[i-k-1]] -= 1
count += check[people[i]]
check[people[i]] += 1
print(count)
< 수 고르기 > - 백준 2230
- 처음에 초기값을 1000000000로 설정했다가 오답이 떴다. 왜 1e9는 안되는 것이지?
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
nums = [int(input()) for _ in range(n)]
nums.sort()
left = 0
right = 0
min_diff = 2e9
while left <= right and right < n:
if nums[right] - nums[left] < m:
right += 1
else:
min_diff = min(min_diff, nums[right] - nums[left])
left += 1
print(min_diff)