結果
| 問題 | No.3509 Get More Money |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 12:28:15 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,334 bytes |
| 記録 | |
| コンパイル時間 | 5,871 ms |
| コンパイル使用メモリ | 343,180 KB |
| 実行使用メモリ | 14,208 KB |
| 最終ジャッジ日時 | 2026-04-18 12:28:43 |
| 合計ジャッジ時間 | 18,429 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using i128 = __int128_t;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N;
long long K;
cin >> N >> K;
vector<long long> 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];
// key = buy cost, value = count of stored jewels with that cost
map<long long, long long> mp;
long long total = 0; // total stored jewels
i128 ans = 0; // profit over initial 10^100
for (int i = 0; i < N; i++) {
// 1) Buy candidates
mp[A[i]] += B[i];
total += B[i];
// 2) Sell up to D[i], always from cheapest profitable jewels
long long remSell = D[i];
while (remSell > 0 && !mp.empty()) {
auto it = mp.begin();
long long cost = it->first;
long long cnt = it->second;
if (cost >= C[i]) break; // no profitable sell anymore
long long x = min(remSell, cnt);
ans += (i128)x * (C[i] - cost);
remSell -= x;
total -= x;
it->second -= x;
if (it->second == 0) mp.erase(it);
}
// 3) Keep only cheapest K jewels for future; discard expensive extras
long long excess = total - K;
while (excess > 0) {
auto it = prev(mp.end());
long long cnt = it->second;
long long x = min(excess, cnt);
it->second -= x;
total -= x;
excess -= x;
if (it->second == 0) mp.erase(it);
}
}
// print i128
if (ans == 0) {
cout << 0 << '\n';
} else {
string s;
while (ans > 0) {
int digit = (int)(ans % 10);
s.push_back(char('0' + digit));
ans /= 10;
}
reverse(s.begin(), s.end());
cout << s << '\n';
}
}
return 0;
}