結果

問題 No.1495 パンの仕入れ
ユーザー MisterMister
提出日時 2021-05-01 11:48:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,254 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 73,408 KB
実行使用メモリ 6,248 KB
最終ジャッジ日時 2023-09-27 01:33:53
合計ジャッジ時間 5,094 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 50 ms
4,380 KB
testcase_03 AC 48 ms
4,380 KB
testcase_04 AC 49 ms
4,380 KB
testcase_05 AC 48 ms
4,380 KB
testcase_06 AC 48 ms
4,376 KB
testcase_07 AC 49 ms
4,384 KB
testcase_08 AC 49 ms
4,376 KB
testcase_09 AC 49 ms
4,380 KB
testcase_10 AC 49 ms
4,376 KB
testcase_11 AC 49 ms
4,380 KB
testcase_12 AC 37 ms
4,376 KB
testcase_13 AC 37 ms
4,376 KB
testcase_14 AC 37 ms
4,376 KB
testcase_15 AC 37 ms
4,384 KB
testcase_16 AC 37 ms
4,380 KB
testcase_17 AC 37 ms
4,384 KB
testcase_18 AC 37 ms
4,376 KB
testcase_19 AC 37 ms
4,380 KB
testcase_20 AC 37 ms
4,376 KB
testcase_21 AC 37 ms
4,384 KB
testcase_22 AC 62 ms
6,248 KB
testcase_23 AC 63 ms
6,248 KB
testcase_24 AC 33 ms
4,376 KB
testcase_25 AC 33 ms
4,380 KB
testcase_26 AC 33 ms
4,380 KB
testcase_27 AC 33 ms
4,380 KB
testcase_28 AC 62 ms
6,188 KB
testcase_29 AC 61 ms
6,096 KB
testcase_30 AC 27 ms
4,380 KB
testcase_31 AC 27 ms
4,380 KB
testcase_32 AC 27 ms
4,380 KB
testcase_33 AC 27 ms
4,380 KB
testcase_34 AC 28 ms
4,380 KB
testcase_35 AC 37 ms
4,384 KB
testcase_36 AC 37 ms
4,376 KB
testcase_37 AC 36 ms
4,380 KB
testcase_38 AC 36 ms
4,380 KB
testcase_39 AC 36 ms
4,380 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using lint = long long;

constexpr lint INF = 1LL << 60;

void solve() {
    int n, m;
    lint k;
    cin >> n >> m >> k;

    vector<lint> ds(n, 0), first(n, 0);
    lint ans = 0;

    while (m--) {
        int x;
        lint y;
        cin >> x >> y;
        --x;

        ds[x] += 2;
        first[x] += y * 2 - 1;
        ans += y * y;
    }

    lint ok = -1, ng = INF;
    while (ng - ok > 1) {
        lint mid = (ok + ng) / 2;

        lint cnt = 0;
        for (int i = 0; i < n && cnt <= k; ++i) {
            if (first[i] < mid) continue;

            if (ds[i] == 0) {
                cnt = k + 1;
            } else {
                cnt += (first[i] - mid) / ds[i] + 1;
            }
        }

        if (cnt >= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (first[i] < ng) continue;

        lint c = (first[i] - ng) / ds[i] + 1;
        k -= c;
        ans -= c * (first[i] * 2 - (c - 1) * ds[i]) / 2;
    }
    ans -= k * ok;

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int q;
    cin >> q;
    while (q--) solve();

    return 0;
}
0