Advertisement
MohamedAbdel3al

Barrels

Oct 3rd, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std ;
  4. #define sz(s) int(s.size())
  5. #define all(s) s.begin() , s.end()
  6. #define getline(s) getline(cin >> ws, s)
  7. #define cin(v) for (auto& i : v) cin >> i ;
  8. #define cout(v) for (auto& i : v) cout << i << " "
  9. #define pb(x) push_back(x)
  10. #define ll long long
  11. #define ull unsigned long long
  12. #define Mod 1'000'000'007
  13. #define INF 2'000'000'000
  14. #define Num_of_Digits(n) ((int)log10(n)+1)
  15. #define fixed(n) fixed << setprecision(n)
  16. #define imin INT_MIN
  17. #define imax INT_MAX
  18. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n" ;
  19.  
  20.  
  21. void ABDEL3AL () {
  22. ios_base::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr) ;
  23. #ifndef ONLINE_JUDGE
  24. freopen("input.txt" , "r" , stdin) , freopen("output.txt" , "w" , stdout) ;
  25. #endif
  26. Time
  27. }
  28.  
  29.  
  30. int main() {
  31. ABDEL3AL() ;
  32. int t ; cin >> t ;
  33. while (t--) {
  34. int n , k , mx = 0 , mn = 0 ;
  35. cin >> n >> k ;
  36. vector < ll > v(n) ;
  37. cin(v) ;
  38. mx = *max_element(all(v)) ;
  39. sort(all(v) , greater <ll> ()) ;
  40. for (int i = 1; i < n; i++) {
  41. if (k > 0) mx += v[i] , v[i] = 0 ;
  42. k-- ;
  43. }
  44. mn = *min_element(all(v)) ;
  45. cout << mx - mn << "\n" ;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement