Ankit_132

C

Oct 25th, 2023
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main() {
  7.     int t;
  8.     cin>>t;
  9.    
  10.     while(t--)
  11.     {
  12.         int n, p, q;
  13.         cin>>n>>p>>q;
  14.  
  15.         vector<ll int> a(n);
  16.         for(auto &e: a)     cin>>e;
  17.  
  18.         sort(a.begin(), a.end());
  19.  
  20.         ll int ans = a.back() - a.front();
  21.  
  22.         for(auto &e: a)      e = abs(e);
  23.  
  24.         if(n > 2)
  25.             sort(a.begin()+1, a.end()-1);
  26.  
  27.         p += q;
  28.  
  29.         for(int i=n-2; i>0; i--)
  30.         {
  31.             if(!p)      break;
  32.             p--;
  33.             ans += a[i];
  34.         }
  35.  
  36.         cout<<ans<<"\n";
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment