C. RationalLee

https://codeforces.com/problemset/problem/1369/C

This is a hard problem on codefores with a diffcuilty score of 1400
It can also be solved by using the priciple of greediness.

void solve(){
int n, k;
cin >> n >> k;

vector a(n);
for (auto& x : a){
cin >> x;
}

sort(a.rbegin(), a.rend());

vector d(k);
for (auto&x : d){
cin >> x;
}

sort(d.begin(), d.end());
long long ans = 0;
for (int i = 0; i < k; ++i){
ans += a[i];
}

for (int i = 0, j = k - 1; i < k; ++i){
if (d[i] == 1){
ans += a[i];
}
else{
j += d[i] - 1;
ans += a[j];
}
}

cout << ans << '\n';
}

posted @ 2024-03-01 22:16  _Yxc  阅读(28)  评论(0)    收藏  举报