Advertisement
yuawn

algo2017_week6_superthief

Nov 13th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define fo(n) for(int i=0;i<n;i++)
  5.  
  6.  
  7. bool cmp( int a , int b ){ return a > b; }
  8.  
  9. int main(){
  10.    
  11.     int T;
  12.     cin >> T;
  13.    
  14.     while( T-- ){
  15.         int tar , now = 0 , n , x[ 400 ];
  16.         bool a = 0;
  17.         vector<int> p;
  18.         cin >> tar >> n;
  19.        
  20.         if( !n ) {
  21.             puts( "impossible" );
  22.             continue;
  23.         }
  24.        
  25.         fo( n ) cin >> x[i];
  26.        
  27.         fo( n ){
  28.             now = 0;
  29.             p.clear();
  30.             if( a ) break;
  31.             for( int j = i ; j < n ; j++ ){
  32.                 now += x[j];
  33.                 p.pb( x[j] );
  34.                 if( now == tar ){
  35.                     cout << p[0];
  36.                     for( int k = 1 ; k < p.size() ; k++ ) cout << ' ' << p[k];
  37.                     cout << endl;
  38.                     a = 1;
  39.                     break;
  40.                 }
  41.                 else if( now > tar ){
  42.                     now -= x[j];
  43.                     p.pop_back();
  44.                 }
  45.             }
  46.         }
  47.         if( !a ) puts( "impossible" );
  48.     }
  49.    
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement