【Codeforces Round #694 (Div. 2) C】Strange Birthday Party
题目链接
翻译
translation
题解
\(k\) 值比较大(对应的礼物贵)的优先安排小的 \(c\),这样节省的 \(money\) 最多。
因为每个 \(k\) 都是要满足的,当然尽可能用便宜点的搪塞最好。。塑料友情。。
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 3e5;
int n, m;
int c[N+10];
pair<int, int> k[N + 10];
int main() {
#ifdef LOCAL_DEFINE
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> k[i].first;
k[i].second = i;
}
sort(k + 1, k + 1 + n);
reverse(k + 1, k + 1 + n);
for (int i = 1; i <= m; i++) {
cin >> c[i];
}
LL sum = 0;
int j = 1;
for (int i = 1; i <= n; i++) {
if (j <= m && j <= k[i].first) {
sum += c[j];
j++;
}
else {
sum += c[k[i].first];
}
}
cout << sum << endl;
}
return 0;
}