結果
| 問題 | No.3509 Get More Money |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 05:05:40 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,627 bytes |
| 記録 | |
| コンパイル時間 | 2,421 ms |
| コンパイル使用メモリ | 342,196 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2026-04-18 05:05:52 |
| 合計ジャッジ時間 | 10,492 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N;
ll K;
cin >> N >> K;
vector<ll> A(N), B(N), C(N), D(N);
for (int i = 0; i < N; i++) cin >> A[i];
for (int i = 0; i < N; i++) cin >> B[i];
for (int i = 0; i < N; i++) cin >> C[i];
for (int i = 0; i < N; i++) cin >> D[i];
// multiset: (cost, count)
map<ll, ll> mp;
ll total = 0;
ll gold = 0;
for (int i = 0; i < N; i++) {
// add buys
mp[A[i]] += B[i];
total += B[i];
// keep only best K (remove largest cost)
while (total > K) {
auto it = prev(mp.end()); // largest cost
ll cost = it->first;
ll cnt = it->second;
ll remove = min(cnt, total - K);
mp[cost] -= remove;
total -= remove;
if (mp[cost] == 0) mp.erase(cost);
}
// sell
ll need = D[i];
while (need > 0 && !mp.empty()) {
auto it = mp.begin(); // smallest cost
ll cost = it->first;
ll cnt = it->second;
ll take = min(cnt, need);
gold += take * (C[i] - cost);
mp[cost] -= take;
total -= take;
need -= take;
if (mp[cost] == 0) mp.erase(cost);
}
}
cout << gold << '\n';
}
}