Hustlingbeast_Anish

Untitled

Feb 11th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <algorithm>
  3. #define lli long long int
  4. #define li long int
  5. #define mod 1000000007
  6. #define ld long double
  7. #define pb push_back
  8. using namespace std;
  9.  
  10. int main(){
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13.  
  14. lli n,m,k;
  15. cin>>n>>m>>k;
  16.  
  17. // lli p=m-1;
  18. lli h=0;
  19. lli arr[n];
  20. for (int i = 0; i < n; i++)
  21. {
  22. cin>>arr[i];
  23. }
  24. lli ans=0;
  25. lli ct=0;
  26. // lli g=0;
  27. sort(arr,arr+n,::greater<int> () );
  28. while(m--){
  29. if(h==0){
  30. ans=ans+arr[h];
  31. ct++;
  32. }
  33. if(h==1){
  34. ans=ans+arr[h];
  35. ct=0;
  36. h==0;
  37. }
  38. if(ct==k){
  39. ct=0;
  40. h=1;
  41. // ans=ans%mod+arr[1];
  42. }
  43.  
  44. }
  45. cout<<ans<<endl;
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment