-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexactChangeOJ.cpp
62 lines (51 loc) · 1.15 KB
/
exactChangeOJ.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int testCase;
cin >> testCase;
for (int c = 1; c <= testCase; ++c)
{
int total;
cin >> total;
int n;
cin >> n;
if (total == 0 && n == 0)
{
cout << "0 0\n";
}
vector<int> a(n);
for (int i = 0; i <= n - 1; ++i)
{
cin >> a[i];
}
vector<int> dp(total + 10001, 10001);
dp[0] = 0;
for (int i = 0; i <= n - 1; ++i)
{
for (int j = total + 10000; j >= a[i]; --j)
{
dp[j] = min(dp[j], dp[j - a[i]] + 1);
}
}
int ans = total;
while (ans <= total + 10000 && dp[ans] == 10001)
{
++ans;
}
cout << ans << ' ' << dp[ans] << '\n';
}
cout.flush();
return 0;
}