-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimetime.cpp
45 lines (38 loc) · 855 Bytes
/
primetime.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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
int solve() {
int n;
cin >> n;
vi a(n);
for(int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
for (int j = 0; j < y; j++) {
a.emplace_back(x);
}
}
int best = 0;
for (int i = 1; i < pow(2, a.size() - 1) - 1; i++) {
int sum = 0;
int prod = 1;
for (int j = 0; j < a.size(); j++) {
int val = (i >> j & 1);
if (val == 0) sum += a[j];
else
prod *= a[j];
}
if (sum == prod) best = max(best, sum);
}
return best;
}
int main() {
ll t;
cin >> t;
for (ll i = 0; i < t; i++) {
cout << "Case #" << i + 1 << ": " << solve() << endl;
}
return 0;
}