Advertisement
apl-mhd

wedding

Aug 13th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main(int argc, char **argv)
  11. {
  12.  
  13.     int testCase;
  14.     cin>>testCase;
  15.    
  16.     while(testCase--){
  17.  
  18.     int totalAmount, cloths;
  19.    
  20.     vector<int>garment[cloths];
  21.     cin>>totalAmount>>cloths;
  22.    
  23.     for(int m=0; m<cloths; m++){
  24.         int tklen;
  25.         cin>>tklen;
  26.         for(int n=0; n<tklen; n++){
  27.            
  28.         int tk;
  29.         cin>>tk;
  30.     garment[m].push_back(tk);
  31.    
  32.    
  33. }
  34.  
  35. }
  36.    
  37.     for(int i=0; i<cloths-1; i++){
  38.        
  39.         int secondSize = garment[i+1].size();
  40.        
  41.         for(int j=0; j<garment[i].size(); j++){
  42.                 int x = garment[i][j];
  43.            
  44.             for(int k=0; k<secondSize; k++){
  45.                
  46.                 int y = garment[i+1][k];
  47.                
  48.                 if (x+y < totalAmount & (i!=3-1))
  49.                     garment[i+1].push_back(x+y);
  50.                 else if(x+y<= totalAmount)
  51.                     garment[i+1].push_back(x+y);
  52.                
  53.                 }
  54.            
  55.                
  56.             }
  57.            
  58.             garment[i+1].erase(garment[i+1].begin(),garment[i+1].begin()+secondSize);
  59.        
  60.         }
  61.        
  62.        
  63.     ///for(int i=0; i<cloths; i++){
  64.        
  65.         reverse(garment[cloths-1].begin(), garment[cloths-1].end());
  66.        
  67.         for (int j=0; j<garment[i].size(); j++){
  68.            
  69.             cout<<garment[cloths-1][j]<<" ";
  70.             }
  71.            
  72.         cout<<endl<<"\n";
  73.        
  74.         //}
  75.    
  76. }
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement