题解:P17302 [ICPC 2026 Xi'an I] VIP Coupon
an_unique_Gambler · · 题解
对于第
所以考虑这样的贪心:
因此我们将所有纪念品压入一个大根堆,按照
当遍历到第
- 取出堆顶。
- 如果
b_i + \max(a_j - c_i, 0) < a_j :- 答案加上
\max(a_j - c_i, 0) 。 - 将第
i 张优惠券也当做一个物品压入堆中。
- 答案加上
- 如果
b_i + \max(a_j - c_i, 0) \ge a_j :- 购买该优惠券并没有什么价值,直接忽略即可。
最后已经没有优惠券了,把堆中所有剩下的物品全部加一起即可。
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
struct Node{
int b, c;
}x[N];
priority_queue<int> q;
int a[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while (T--){
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i], q.push(a[i]);
for (int i = 1; i <= m; i++) cin >> x[i].b;
for (int i = 1; i <= m; i++) cin >> x[i].c;
sort(x + 1, x + m + 1, [&](Node a, Node b){
return a.c > b.c;
});
long long ans = 0;
for (int i = 1; i <= m; i++){
int v = q.top();
if (x[i].b + max(v - x[i].c, 0) >= v) continue;
else{
ans += max(v - x[i].c, 0);
q.pop();
q.push(x[i].b);
}
}
while (!q.empty()){
ans += q.top();
q.pop();
}
cout << ans << '\n';
}
return 0;
}