Advertisement
Junaid_Hossain

Maximum Deliciousness

Aug 30th, 2023
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int> cakes(int n, int k, int l){
  5.     vector<int> indices;
  6.     int turn=l;
  7.     while(turn<=n){
  8.         indices.push_back(turn);
  9.         turn = turn+k;
  10.     }
  11.  
  12.     return indices;
  13. }
  14.  
  15. int main(){
  16.     int t;
  17.     cin >> t;
  18.  
  19.     while(t--){
  20.         int n, k, l;
  21.         cin >> n >> k >> l;
  22.         int deliciousness[n];
  23.         int sum=0;
  24.  
  25.         for(int i=0; i<n; i++){
  26.             cin >> deliciousness[i];
  27.         }
  28.  
  29.         sort(deliciousness, deliciousness+n, greater<int>());
  30.  
  31.         vector<int> indices=cakes(n, k, l);
  32.  
  33.         for(int i=0; i<indices.size(); i++){
  34.             sum=sum+deliciousness[indices[i]];
  35.             //cout << indices[i] << " ";
  36.         }
  37.  
  38.  
  39.         cout << sum << "\n";
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement