题解:P16494 樱蕊初含雪,惜春时易逝
思路:
不难发现,配对总美观度为所有配对的花的美观度之和也就是
那么最多能配多少对?
我们设一个
当
当
当
当
那么此时最优策略就是让多数色中最小的
此时总美观度为
当
当
多数色取
可得答案
即去掉排序后中间的
思路已经很清晰了,接下来代码奉上:
代码:
#include<iostream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 50005;
ll T,n,x,y,z;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>T;
while(T --){
cin>>n>>x>>y>>z;
int m = max({x,y,z});
ll a[N];
for(int i = 1; i <= n; i ++)cin>>a[i];
sort(a + 1,a + 1 + n);
ll s[N];
s[0] = 0;
for(int i = 1; i <= n; i ++)s[i] = s[i - 1] + a[i];
ll ans;
if(m <= n / 2){
if(n % 2 == 0)ans = s[n];
else ans = s[n] - a[1];
}
else{
ans = s[n] - (s[m] - s[n - m]);
}
cout<<ans<<endl;
}
return 0;
}