115552024-10-26 19:03:36balintPontos átlag 2python3Accepted 100/1001.879s26228 KiB
def main():
    N, K = map(int, input().strip().split())
    nums = list(map(int, input().strip().split()))

    target_sum = K * N 

    def can_achieve_with_C(C):
        lower_sum, upper_sum = 0, 0
        for num in nums:
            lower_sum += max(num - C, 1)
            upper_sum += num + C

        return lower_sum <= target_sum <= upper_sum
    
    left, right = 0, max(abs(K - min(nums)), abs(K - max(nums)))
    while left < right:
        mid = (left + right) // 2
        if can_achieve_with_C(mid):
            right = mid 
        else:
            left = mid + 1
    
    print(left)

main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted16ms3316 KiB
2Accepted16ms3128 KiB
subtask210/10
3Accepted14ms3060 KiB
4Accepted16ms3128 KiB
5Accepted16ms3076 KiB
6Accepted16ms3124 KiB
7Accepted16ms3128 KiB
8Accepted16ms2972 KiB
subtask320/20
9Accepted152ms6812 KiB
10Accepted153ms7088 KiB
11Accepted194ms6468 KiB
12Accepted199ms6456 KiB
13Accepted204ms6780 KiB
14Accepted153ms7064 KiB
15Accepted204ms7032 KiB
16Accepted203ms7220 KiB
17Accepted16ms3128 KiB
subtask424/24
18Accepted26ms3120 KiB
19Accepted26ms3124 KiB
20Accepted25ms3320 KiB
21Accepted19ms3132 KiB
22Accepted20ms3248 KiB
23Accepted23ms3016 KiB
24Accepted24ms3012 KiB
25Accepted25ms3052 KiB
26Accepted24ms3128 KiB
27Accepted19ms3116 KiB
28Accepted17ms3128 KiB
subtask546/46
29Accepted203ms7112 KiB
30Accepted804ms26228 KiB
31Accepted790ms15856 KiB
32Accepted1.179s21184 KiB
33Accepted1.345s25000 KiB
34Accepted1.578s24980 KiB
35Accepted1.745s24844 KiB
36Accepted1.781s24908 KiB
37Accepted1.879s24836 KiB
38Accepted1.83s24620 KiB
39Accepted677ms10644 KiB
40Accepted41ms3640 KiB
41Accepted17ms3128 KiB