-
Notifications
You must be signed in to change notification settings - Fork 2
/
11517.cpp
36 lines (34 loc) · 847 Bytes
/
11517.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
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
using namespace std;
void find_min_sum(vector<int>& collection, vector<int>& min_sum)
{
vector<int>::iterator C;
int i;
min_sum[0] = 0;
fill(min_sum.begin()+1, min_sum.end(), INT_MAX);
for(C = collection.begin(); C != collection.end(); C++)
for(i = 10000-*C; i >= 0; i--)
if(min_sum[i] != INT_MAX)
if(min_sum[i]+1 < min_sum[i+*C])
min_sum[i+*C] = min_sum[i]+1;
}
int main()
{
int cases, cost, n, i;
vector<int> collection(101);
vector<int> min_sum(10001, 0);
cin >> cases;
while(cases--)
{
cin >> cost >> n;
collection.resize(n);
for(i = 0; i < n; i++)
cin >> collection[i];
find_min_sum(collection, min_sum);
for(i = cost; min_sum[i] == INT_MAX; i++);
cout << i << ' ' << min_sum[i] << endl;
}
}