1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 5 int compare(void const * i,void const * j); 6 int main() 7 { 8 //freopen("acm.acm","r",stdin); 9 int num; 10 int i; 11 int j; 12 int st; 13 int sum; 14 int f_num; 15 int * a; 16 cin>>num; 17 j = 1; 18 while(num --) 19 { 20 cin>>st; 21 cin>>f_num; 22 sum = 0; 23 a = new int[f_num]; 24 for(i = 0; i < f_num; ++ i) 25 { 26 cin>>a[i]; 27 } 28 qsort(a,f_num,sizeof(int),compare); 29 for(i = 0; i < f_num; ++ i) 30 { 31 sum += a[i]; 32 if(sum >= st) 33 { 34 cout<<"Scenario #"<<j<<":"<<endl; 35 cout<<i+1<<endl; 36 ++j; 37 cout<<endl; 38 break; 39 } 40 } 41 if(i == f_num) 42 { 43 cout<<"Scenario #"<<j<<":"<<endl; 44 cout<<"impossible"<<endl; 45 ++ j; 46 cout<<endl; 47 } 48 delete[] a; 49 50 } 51 } 52 int compare(void const * i,void const * j) 53 { 54 return *((int *)j) - *((int *)i); 55 }