-
Notifications
You must be signed in to change notification settings - Fork 0
/
1398D_ColoredRectangles.cpp
119 lines (110 loc) · 3.1 KB
/
1398D_ColoredRectangles.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Created by ishaanjav
* github.com/ishaanjav
* Codeforces Solutions: https://github.com/ishaanjav/Codeforces-Solutions
*/
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define SET(a, c) memset(a, c, sizeof a)
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#include <string>
#include <vector>
typedef vector<int> vi;
#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>
/*
10 1 1
11 7 20 15 19 14 2 4 13 14
8
11
*/
vector<ll> a, b, c;
bool used[202][202][202];
ll dp[202][202][202];
ll solve(ll A, ll B, ll C) {
if ((A < 1 && B < 1) || (A < 1 && C < 1) || (C < 1 && B < 1)) return 0;
ll oA = A, oB = B, oC = C;
// A = max(A, 1ll), B = max(B, 1ll), C = max(C, 1ll);
if (used[A][B][C]) {
// cout << " " << A << " " << B << " " << C << " == " << dp[A][B][C] << endl;
return dp[A][B][C];
}
// A = oA, B = oB, C = oC;
ll ways = 0;
if (A >= 1 && B >= 1) ways = max(ways, solve(A - 1, B - 1, C) + a[A] * b[B]);
if (C >= 1 && B >= 1) ways = max(ways, solve(A, B - 1, C - 1) + c[C] * b[B]);
if (C >= 1 && A >= 1) ways = max(ways, solve(A - 1, B, C - 1) + c[C] * a[A]);
used[A][B][C] = 1;
dp[A][B][C] = ways;
// cout << A << " " << B << " " << C << " == " << ways << endl;
return ways;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int A, B, C;
cin >> A >> B >> C;
a.resize(A + 1);
b.resize(B + 1);
c.resize(C + 1);
a[0] = 0, b[0] = 0, c[0] = 0;
for (int i = 0; i < A; i++) cin >> a[i + 1];
for (int i = 0; i < B; i++) cin >> b[i + 1];
for (int i = 0; i < C; i++) cin >> c[i + 1];
sort(all(a));
sort(all(b));
sort(all(c));
// A--, B--, C--;
ll area = solve(A, B, C);
/* while ((A >= 0 && B >= 0) || (B >= 0 || C >= 0) || (A >= 0 && C >= 0)) {
vector<pii> v;
v.pb(mp((A >= 0 ? a[A] : -1), 1));
v.pb(mp((B >= 0 ? b[B] : -1), 2));
v.pb(mp((C >= 0 ? c[C] : -1), 3));
sort(all(v));
if (v[1].first == -1) break;
area += v[2].first * v[1].first;
cout << "using " << v[2].first << " and " << v[1].first << endl;
if (v[1].second == 1 || v[2].second == 1) A--;
if (v[1].second == 2 || v[2].second == 2) B--;
if (v[1].second == 3 || v[2].second == 3) C--;
/* bool uA = false, uB = false, uC = false;
if (A >= 0) c1 = a[A];
if (B >= 0) {
if (c1 == -1) {
uB = true;
c1 = b[B];
} else if (b[B] > c1) {
c2 = c1;
c1 = b[B];
}
}
if (C >= 0) {
if (c2 == -1)
c2 = c[C];
else if (c[C] > c1) {
c2 = c1;
c1 = c[C];
}
}
area += c1 * c2; */
cout << area;
}