题目链接:CodeForces 1132B【Discounts】
思路
因为使用coupons购买q[i]块巧克力,不需要付最便宜的那块巧克力的钱,所以为了使得优惠最大化,所以可以在使用优惠券的时候购买最贵的p[i]块巧克力,所以计算所有巧克力价格高之和和排序后很快能得到答案。
代码
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
const int N = 3e5 + 10;
ll a[N], q[N], sum, n, m;
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> q[i];
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= m; i++) {
cout << sum - a[n - q[i] + 1] << endl;
}
}
int main() {
int t = 1;
while (t--) {
solve();
}
return 0;
}
标签:1132B,巧克力,int,CodeForces,Discounts,include
From: https://www.cnblogs.com/againss/p/18336850