結果

問題 No.1495 パンの仕入れ
ユーザー MisterMister
提出日時 2021-05-01 11:39:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 73,212 KB
実行使用メモリ 6,208 KB
最終ジャッジ日時 2023-09-27 01:24:08
合計ジャッジ時間 6,092 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using lint = long long;

constexpr lint INF = 1 << 30;

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] <= ok) continue;

        lint c = (first[i] - ok) / ds[i] + 1;
        k -= c;
        ans -= first[i] * c - c * (c - 1) / 2 * ds[i];
    }
    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