题解:P16494 樱蕊初含雪,惜春时易逝
思路
本题主要要分两种情况进行讨论。
-
x+y \ge z -
x+y < z
第一种情况 x+y \ge z 。
这种情况下又分两种情况,第一种情况是
第二种情况 x+y < z 。
这个时候颜色为黄色的花(共有
注意数组一定要降序排序。
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
long long a[50007];
bool cmp(long long x,long long y){
return x > y;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t;
cin >> t;
while (t--){
int n,x,y,z;
int nn;
cin >> n >> x >> y >> z;
nn = n;
for (int i = 1;i <= n;i++) cin >> a[i];
sort(a+1,a+1+n,cmp);
if (x+y < z){
long long sum = 0;
for (int i = 1;i <= x+y;i++) sum += a[i];
for (int i = n-x-y+1;i <= n;i++) sum += a[i];
cout << sum << '\n';
}
else{
long long sum = 0;
for (int i = 1;i <= n-n%2;i++) sum += a[i];
cout << sum << '\n';
}
}
return 0;
}