fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n,x,y;cin>>n>>x>>y;
  7. vector<int>a(n),b(n),diff(n);
  8. for(int i=0;i<n;i++){
  9. cin>>a[i];
  10. }
  11. int old_sum=0;
  12. for(int i=0;i<n;i++){
  13. cin>>b[i];
  14. old_sum+=b[i];
  15. diff[i]=a[i]-b[i];
  16.  
  17. }
  18. int a_count=1,Optimal_diff=0;
  19. sort(diff.begin(),diff.end());
  20. while(a_count<=x){
  21. int temp=0;
  22. if(n-a_count>y){
  23. a_count++;
  24. continue;
  25. }
  26. for(int j=0;j<a_count;j++){
  27. temp+=diff[n-1-j];
  28. }
  29. Optimal_diff=max(temp,Optimal_diff);
  30.  
  31. a_count++;
  32.  
  33. }
  34.  
  35.  
  36. cout<<Optimal_diff+old_sum<<endl;
  37.  
  38.  
  39. }
  40.  
Success #stdin #stdout 0s 5324KB
stdin
5 3 3
1 2 3 4 5
5 4 3 2 1
stdout
21