結果
| 問題 | No.3509 Get More Money |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-19 16:37:06 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 127 ms / 2,000 ms |
| コード長 | 1,803 bytes |
| 記録 | |
| コンパイル時間 | 2,832 ms |
| コンパイル使用メモリ | 343,068 KB |
| 実行使用メモリ | 21,632 KB |
| 最終ジャッジ日時 | 2026-04-19 16:37:31 |
| 合計ジャッジ時間 | 15,168 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
void solve() {
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];
map<ll, ll> mp;
ll total = 0;
lll profit = 0;
auto add = [&](ll price, ll count) {
mp[price] += count;
total += count;
};
for (int i = 0; i < N; i++) {
ll a = A[i], b = B[i], c = C[i], d = D[i];
add(a, b);
ll to_sell = d, sold = 0;
while (to_sell > 0 && !mp.empty()) {
auto it = mp.begin();
if (it->first >= c) break;
ll price = it->first;
ll count = it->second;
ll take = min(count, to_sell);
profit += (lll)(c - price) * take;
total -= take;
to_sell -= take;
sold += take;
if (take == count) mp.erase(it);
else it->second -= take;
}
if (sold > 0) add(c, sold);
while (total > K) {
auto it = prev(mp.end());
ll remove = min(it->second, total - K);
total -= remove;
if (remove == it->second) mp.erase(it);
else it->second -= remove;
}
}
if (profit == 0) {
cout << 0 << "\n";
return;
}
string s;
lll p = profit;
while (p > 0) {
s += char('0' + (int)(p % 10));
p /= 10;
}
reverse(s.begin(), s.end());
cout << s << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while (T--) solve();
return 0;
}