結果

問題 No.1495 パンの仕入れ
ユーザー penguinmanpenguinman
提出日時 2021-04-25 02:52:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 489 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 85,436 KB
最終ジャッジ日時 2023-09-26 02:03:19
合計ジャッジ時間 20,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,600 KB
testcase_01 AC 76 ms
71,084 KB
testcase_02 AC 480 ms
79,520 KB
testcase_03 AC 478 ms
79,692 KB
testcase_04 AC 489 ms
79,376 KB
testcase_05 AC 484 ms
80,116 KB
testcase_06 AC 478 ms
79,180 KB
testcase_07 AC 480 ms
79,600 KB
testcase_08 AC 487 ms
79,412 KB
testcase_09 AC 483 ms
79,336 KB
testcase_10 AC 485 ms
79,356 KB
testcase_11 AC 488 ms
79,456 KB
testcase_12 AC 275 ms
78,240 KB
testcase_13 AC 274 ms
78,804 KB
testcase_14 AC 281 ms
78,644 KB
testcase_15 AC 272 ms
78,604 KB
testcase_16 AC 274 ms
78,516 KB
testcase_17 AC 272 ms
78,624 KB
testcase_18 AC 276 ms
78,808 KB
testcase_19 AC 270 ms
78,652 KB
testcase_20 AC 271 ms
78,396 KB
testcase_21 AC 272 ms
78,644 KB
testcase_22 AC 439 ms
85,436 KB
testcase_23 AC 445 ms
85,248 KB
testcase_24 AC 185 ms
80,568 KB
testcase_25 AC 182 ms
80,516 KB
testcase_26 AC 181 ms
80,636 KB
testcase_27 AC 186 ms
80,600 KB
testcase_28 AC 428 ms
85,384 KB
testcase_29 AC 414 ms
85,392 KB
testcase_30 AC 268 ms
78,464 KB
testcase_31 AC 265 ms
78,684 KB
testcase_32 AC 266 ms
78,456 KB
testcase_33 AC 269 ms
78,428 KB
testcase_34 AC 265 ms
78,824 KB
testcase_35 AC 263 ms
78,616 KB
testcase_36 AC 266 ms
78,516 KB
testcase_37 AC 266 ms
78,516 KB
testcase_38 AC 265 ms
78,484 KB
testcase_39 AC 263 ms
78,504 KB
testcase_40 AC 257 ms
78,428 KB
testcase_41 AC 256 ms
78,436 KB
testcase_42 AC 261 ms
78,544 KB
testcase_43 AC 253 ms
78,380 KB
testcase_44 AC 253 ms
78,384 KB
testcase_45 AC 73 ms
71,356 KB
testcase_46 AC 98 ms
76,596 KB
testcase_47 AC 70 ms
71,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
inf = int(2e18)
for _ in range(T):
    N, M, K = map(int, input().split())
    x = [0]*M
    y = [0]*M
    for i in range(M):
        x[i], y[i] = map(int, input().split())
    cnt = [0]*N
    mem = [0]*N
    for i in range(M):
        x[i] -= 1
        cnt[x[i]] += 2
        # (x-y)^2-(x-(y-1))^2 = 2x-2y-1
        mem[x[i]] -= 2*y[i]+1
    left = -inf
    right = inf
    while left+1 < right:
        mid = (right+left)//2
        cnt2 = 0
        for i in range(N):
            if cnt[i] == 0:
                if 0 <= mid:
                    cnt2 += inf
            else:
                # ax+mem[i] ≤ mid
                # ax ≤ mid-mem[i]
                cnt2 += max(0, (mid-mem[i])//cnt[i])
            if cnt2 > K:
                break
        if cnt2 <= K:
            left = mid
        else:
            right = mid
    ans = 0
    flag = False
    num = [0]*N
    cnt2 = 0
    for i in range(N):
        if cnt[i] == 0:
            flag = True
        else:
            num[i] = max(0, (left-mem[i])//cnt[i])
            cnt2 += num[i]
    for i in range(M):
        ans += (num[x[i]]-y[i])*(num[x[i]]-y[i])
    if flag and right > 0:
        cnt2 = K
    ans += (K-cnt2)*right
    print(ans)
0