Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define fo(n) for(int i=0;i<n;i++)
- bool cmp( int a , int b ){ return a > b; }
- int main(){
- int T;
- cin >> T;
- while( T-- ){
- int tar , now = 0 , n , x[ 400 ];
- bool a = 0;
- vector<int> p;
- cin >> tar >> n;
- if( !n ) {
- puts( "impossible" );
- continue;
- }
- fo( n ) cin >> x[i];
- fo( n ){
- now = 0;
- p.clear();
- if( a ) break;
- for( int j = i ; j < n ; j++ ){
- now += x[j];
- p.pb( x[j] );
- if( now == tar ){
- cout << p[0];
- for( int k = 1 ; k < p.size() ; k++ ) cout << ' ' << p[k];
- cout << endl;
- a = 1;
- break;
- }
- else if( now > tar ){
- now -= x[j];
- p.pop_back();
- }
- }
- }
- if( !a ) puts( "impossible" );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement