比赛时题意没理解到位,没想到 vt.push_back(-p[j] - max(a[j],0));这一步。。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100010;
int a[N],p[N],b[N];
int main(){
ios_base::sync_with_stdio(false);
int n,m;
cin >> n >> m;
ll zero_total = 0,one_total=0;
for(int i = 1;i<=n;i++) cin >> a[i];
for(int i = 1;i<=n;i++) cin >> p[i];
for(int i = 1;i<=n;i++) cin >> b[i];
ll ans = 0;
for(int i = 0;i<=1;i++){
vector<int> vt;
ll cur = 0;
for(int j = 1;j<=n;j++){
if(b[j] == i){
cur += max(a[j],0);
vt.push_back(-p[j] - max(a[j],0));
}else{
vt.push_back(max(a[j],0) - p[j]);
}
}
sort(vt.begin(),vt.end(),greater<int>());
for(int j = 0;j<n&j<m;j++){
cur += max(vt[j],0);
}
ans = max(ans,cur);
}
cout << ans << endl;
return 0;
}
|