結果

問題 No.1495 パンの仕入れ
ユーザー penguinmanpenguinman
提出日時 2021-04-25 02:49:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 85,336 KB
最終ジャッジ日時 2023-09-17 13:59:56
合計ジャッジ時間 17,532 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,012 KB
testcase_01 AC 76 ms
71,324 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 279 ms
78,444 KB
testcase_13 AC 282 ms
78,728 KB
testcase_14 AC 292 ms
78,704 KB
testcase_15 AC 277 ms
78,304 KB
testcase_16 AC 279 ms
78,524 KB
testcase_17 AC 279 ms
78,408 KB
testcase_18 AC 277 ms
78,748 KB
testcase_19 AC 278 ms
78,592 KB
testcase_20 AC 277 ms
78,604 KB
testcase_21 AC 276 ms
78,412 KB
testcase_22 AC 444 ms
85,336 KB
testcase_23 AC 447 ms
85,104 KB
testcase_24 AC 192 ms
80,576 KB
testcase_25 AC 192 ms
80,620 KB
testcase_26 AC 191 ms
80,444 KB
testcase_27 AC 191 ms
80,540 KB
testcase_28 AC 427 ms
85,304 KB
testcase_29 AC 426 ms
85,292 KB
testcase_30 AC 270 ms
78,372 KB
testcase_31 AC 268 ms
78,264 KB
testcase_32 AC 268 ms
78,348 KB
testcase_33 AC 269 ms
78,208 KB
testcase_34 AC 268 ms
78,688 KB
testcase_35 AC 270 ms
78,388 KB
testcase_36 AC 271 ms
78,320 KB
testcase_37 AC 269 ms
78,292 KB
testcase_38 AC 270 ms
78,352 KB
testcase_39 AC 269 ms
78,452 KB
testcase_40 AC 261 ms
78,208 KB
testcase_41 AC 259 ms
78,736 KB
testcase_42 AC 260 ms
78,136 KB
testcase_43 AC 258 ms
78,320 KB
testcase_44 AC 259 ms
78,376 KB
testcase_45 AC 76 ms
71,288 KB
testcase_46 WA -
testcase_47 AC 75 ms
71,260 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:
        cnt2 = K
    ans += (K-cnt2)*right
    print(ans)
0