forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorders.cpp
71 lines (59 loc) · 1.27 KB
/
orders.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
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
void process(vector<int>& v, vector<int> costs, int order) {
vector<int> ans;
if(v[order] == -2) {
cout << "Impossible" << endl;
return;
}
if(v[order] == -1) {
cout << "Ambiguous" << endl;
return;
}
while(order > 0) {
ans.push_back(v[order]+1);
order -= costs[v[order]];
}
if(order < 0) {
cout << "Ambiguous" << endl;
return;
}
sort(ans.begin(), ans.end());
for(auto i : ans) {
cout << i << " ";
}
cout << endl;
}
int main() {
vector<int> v(32000, -2);
v[0] = 0;
int n;
cin >> n;
vector<int> costs(n);
for(auto& i : costs) {
cin >> i;
}
for(int i = 0; i < n; i++) {
int cost = costs[i];
for(int j = 0; j <= 30000; j++) {
if(v[j] >= 0) {
if(v[j+cost] == -2) {
v[j+cost] = i;
}
else {
v[j+cost] = -1;
}
}
if(v[j] == -1) {
v[j+cost] = -1;
}
}
}
int q;
cin >> q;
for(int i = 0; i < q; i++) {
int order;
cin >> order;
process(v, costs, order);
}
}