-
Notifications
You must be signed in to change notification settings - Fork 0
/
google1.cpp
89 lines (71 loc) · 1.91 KB
/
google1.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for(int z = 1; z <= t; z++) {
int x;
cin >> x;
int n;
vector<int> v;
cin >> n;
for(int i = 0; i < n; i++) {
string t;
int h;
cin >> t >> h;
v.push_back(h);
}
int m;
vector<int> v1;
cin >> m;
for(int i = 0; i < m; i++) {
string t;
int h;
cin >> t >> h;
v1.push_back(h);
}
vector<int> prices;
int flag1 = 0, flag2 = 0;
int max = v[0];
for(int i = 0; i < v.size(); i++) {
prices.push_back(v[i]);
for(int j = 0; j < v1.size(); j++) {
int sum = v[i] + v1[j];
prices.push_back(sum);
}
if(flag1 == 0) {
for(int j = 0; j < v1.size(); j++) {
for(int k = j+1; k < v1.size(); k++) {
int sum = v[i] + v1[j] + v1[k];
prices.push_back(sum);
}
}
}
}
vector<int> diff;
for(int i = 0; i < prices.size(); i++) {
int d = x - prices[i];
diff.push_back(d);
}
int minimum = INT_MAX;
for(int i = 0; i < diff.size(); i++) {
if(abs(diff[i]) < minimum) {
minimum = abs(diff[i]);
}
}
vector<int> indexes;
for(int i = 0; i < diff.size(); i++) {
if(abs(diff[i]) == minimum) {
indexes.push_back(i);
}
}
int min = INT_MAX;
for(int i = 0; i < indexes.size(); i++) {
if(prices[indexes[i]] < min) {
min = prices[indexes[i]];
}
}
cout << "Case #" << z << ": " << min << "\n";
}
return 0;
}