結果
| 問題 | No.3509 Get More Money |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 12:35:23 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,140 bytes |
| 記録 | |
| コンパイル時間 | 3,025 ms |
| コンパイル使用メモリ | 343,224 KB |
| 実行使用メモリ | 14,208 KB |
| 最終ジャッジ日時 | 2026-04-18 12:35:56 |
| 合計ジャッジ時間 | 18,603 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using i128 = __int128_t;
static void print_i128(i128 x) {
if (x == 0) {
cout << 0 << '\n';
return;
}
string s;
while (x > 0) {
s.push_back(char('0' + (int)(x % 10)));
x /= 10;
}
reverse(s.begin(), s.end());
cout << s << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N;
int64 K;
cin >> N >> K;
vector<int64> 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 = sell price, value = count of unmatched future sell slots
map<int64, int64> mp;
int64 sz = 0;
i128 ans = 0;
for (int i = N - 1; i >= 0; i--) {
// 1) Add today's sell slots
mp[C[i]] += D[i];
sz += D[i];
// 2) Use today's buys to match highest profitable sell slots
int64 rem = B[i];
while (rem > 0 && !mp.empty()) {
auto it = prev(mp.end()); // largest sell price
int64 price = it->first;
int64 cnt = it->second;
if (price <= A[i]) break; // no positive profit anymore
int64 take = min(rem, cnt);
ans += (i128)take * (price - A[i]);
rem -= take;
sz -= take;
it->second -= take;
if (it->second == 0) mp.erase(it);
}
// 3) At most K sell slots can be carried further to the past
while (sz > K) {
auto it = mp.begin(); // discard smallest sell prices
int64 cnt = it->second;
int64 drop = min<int64>(cnt, sz - K);
it->second -= drop;
sz -= drop;
if (it->second == 0) mp.erase(it);
}
}
print_i128(ans);
}
return 0;
}