Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main() {
- int t;
- cin>>t;
- while(t--)
- {
- int n, p, q;
- cin>>n>>p>>q;
- vector<ll int> a(n);
- for(auto &e: a) cin>>e;
- sort(a.begin(), a.end());
- ll int ans = a.back() - a.front();
- for(auto &e: a) e = abs(e);
- if(n > 2)
- sort(a.begin()+1, a.end()-1);
- p += q;
- for(int i=n-2; i>0; i--)
- {
- if(!p) break;
- p--;
- ans += a[i];
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment