forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamps.cpp
45 lines (45 loc) · 871 Bytes
/
stamps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 2011-04-05
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
int i;
static int a[1000000];
for (i=0; i<T; i++)
{
int x,n,j;
printf("Scenario #%d:\n",i+1);
scanf("%d %d",&x,&n);
for (j=0; j<n; j++)
scanf("%d",a+j);
sort(a,a+n,greater<int>());
int sum=0;
j=0;
while (j<n&&sum<x)
sum+=a[j++];
if (sum>=x) printf("%d\n",j);
else puts("impossible");
putchar('\n');
}
return 0;
}