結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,552 KB
testcase_01 AC 77 ms
75,696 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 270 ms
78,540 KB
testcase_13 AC 278 ms
78,464 KB
testcase_14 AC 278 ms
78,516 KB
testcase_15 AC 273 ms
78,956 KB
testcase_16 AC 276 ms
78,776 KB
testcase_17 AC 275 ms
78,816 KB
testcase_18 AC 280 ms
78,688 KB
testcase_19 AC 280 ms
78,788 KB
testcase_20 AC 269 ms
78,632 KB
testcase_21 AC 269 ms
78,728 KB
testcase_22 AC 462 ms
85,592 KB
testcase_23 AC 473 ms
85,404 KB
testcase_24 AC 188 ms
80,672 KB
testcase_25 AC 185 ms
80,768 KB
testcase_26 AC 186 ms
80,640 KB
testcase_27 AC 188 ms
80,476 KB
testcase_28 AC 441 ms
85,564 KB
testcase_29 AC 463 ms
85,540 KB
testcase_30 AC 265 ms
78,596 KB
testcase_31 AC 269 ms
78,544 KB
testcase_32 AC 266 ms
78,540 KB
testcase_33 AC 266 ms
78,308 KB
testcase_34 AC 266 ms
78,552 KB
testcase_35 AC 264 ms
78,604 KB
testcase_36 AC 261 ms
78,140 KB
testcase_37 AC 264 ms
78,416 KB
testcase_38 AC 262 ms
78,344 KB
testcase_39 AC 263 ms
78,892 KB
testcase_40 AC 254 ms
78,700 KB
testcase_41 AC 256 ms
78,888 KB
testcase_42 AC 257 ms
78,476 KB
testcase_43 AC 253 ms
78,660 KB
testcase_44 AC 255 ms
78,376 KB
testcase_45 AC 72 ms
71,220 KB
testcase_46 WA -
testcase_47 AC 73 ms
71,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
inf = int(1e19)
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