Saleh127

CF 1430B

Oct 11th, 2020 (edited)
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12.  
  13. ll a[200005],c,d,e=0,f,i,j,k,l;
  14. cin>>c>>d;
  15. for(i=0;i<c;i++)
  16. {
  17. cin>>a[i];
  18. }
  19. sort(a,a+c);
  20. e+=a[c-1];
  21. for(i=c-2;i>=0 && d>0;i--)
  22. {
  23. d--;
  24. e+=a[i];
  25. }
  26. cout<<e<<endl;
  27. }
  28.  
  29.  
  30. return 0;
  31. }
  32.  
RAW Paste Data Copied