258일차 - BOJ no.2805


https://www.acmicpc.net/problem/2805

My Solution

import sys
n, m = list(map(int,sys.stdin.readline().rstrip().split()))
arr = list(map(int, sys.stdin.readline().rstrip().split()))

arr.sort()
start, end = 1, arr[-1]

while start <= end:
    total = 0
    mid = (start + end) // 2
    for i in arr:
        if i <= mid:
            continue
        else:
            total += i - mid
    if total >= m:
        start = mid + 1
    else:
        end = mid - 1
print(end)

좋은 웹페이지 즐겨찾기