結果
問題 |
No.1495 パンの仕入れ
|
ユーザー |
|
提出日時 | 2021-05-01 11:41:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,250 bytes |
コンパイル時間 | 644 ms |
コンパイル使用メモリ | 73,084 KB |
最終ジャッジ日時 | 2025-01-21 05:03:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 35 WA * 11 |
ソースコード
#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] < ng) continue; lint c = (first[i] - ng) / 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; }