#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "CloudComputing"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int C = 100001;
const ll INF = 1e18;
struct order{
int type; /// 0 buy, 1: sell
int c, f, v;
order(int _t, int _c, int _f, int _v){
type = _t;
c = _c;
f = _f;
v = _v;
}
};
int n, m;
ll dp[C], nxtDp[C];
vector <order> ords;
void readInput(){
cin >> n;
for(int i = 1; i <= n; i++){
int c, f, v;
cin >> c >> f >> v;
ords.push_back(order(0, c, f, -v));
}
cin >> m;
for(int i = 1; i <= m; i++){
int c, f, v;
cin >> c >> f >> v;
ords.push_back(order(1, -c, f, v));
}
}
void solve(){
sort(ords.begin(), ords.end(), [](const order &a, const order &b){
if (a.f != b.f)
return a.f > b.f;
return a.type < b.type;
});
dp[0] = 0;
for(int i = 1; i < C; i++)
dp[i] = -INF;
for(order o : ords){
int c = o.c;
int v = o.v;
for(int i = 0; i < C; i++)
nxtDp[i] = -INF;
for(int i = 0; i < C; i++){
nxtDp[i] = max(nxtDp[i], dp[i]);
if (0 <= i + c && i + c < C)
nxtDp[i + c] = max(nxtDp[i + c], dp[i] + v);
}
for(int i = 0; i < C; i++)
swap(dp[i], nxtDp[i]);
}
ll res = -1;
for(int i = 0; i < C; i++)
res = max(res, dp[i]);
cout << res;
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
readInput();
solve();
return 0;
}
Compilation message
clo.cpp: In function 'int main()':
clo.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
25 ms |
1884 KB |
Output is correct |
4 |
Correct |
47 ms |
1880 KB |
Output is correct |
5 |
Correct |
434 ms |
1880 KB |
Output is correct |
6 |
Correct |
427 ms |
1884 KB |
Output is correct |
7 |
Correct |
456 ms |
1884 KB |
Output is correct |
8 |
Correct |
441 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1884 KB |
Output is correct |
2 |
Correct |
3 ms |
1884 KB |
Output is correct |
3 |
Correct |
27 ms |
1884 KB |
Output is correct |
4 |
Correct |
36 ms |
1884 KB |
Output is correct |
5 |
Correct |
216 ms |
1880 KB |
Output is correct |
6 |
Correct |
227 ms |
1880 KB |
Output is correct |
7 |
Correct |
461 ms |
2088 KB |
Output is correct |
8 |
Correct |
511 ms |
1884 KB |
Output is correct |
9 |
Correct |
453 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1884 KB |
Output is correct |
2 |
Correct |
9 ms |
1884 KB |
Output is correct |
3 |
Correct |
58 ms |
1884 KB |
Output is correct |
4 |
Correct |
49 ms |
1884 KB |
Output is correct |
5 |
Correct |
93 ms |
1880 KB |
Output is correct |
6 |
Correct |
84 ms |
1984 KB |
Output is correct |
7 |
Correct |
117 ms |
2000 KB |
Output is correct |
8 |
Correct |
115 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
5 ms |
1884 KB |
Output is correct |
3 |
Correct |
364 ms |
1884 KB |
Output is correct |
4 |
Correct |
448 ms |
1880 KB |
Output is correct |
5 |
Correct |
879 ms |
2136 KB |
Output is correct |
6 |
Correct |
902 ms |
2152 KB |
Output is correct |
7 |
Correct |
879 ms |
2136 KB |
Output is correct |
8 |
Correct |
897 ms |
2148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
36 ms |
1884 KB |
Output is correct |
3 |
Correct |
180 ms |
1880 KB |
Output is correct |
4 |
Correct |
459 ms |
1884 KB |
Output is correct |
5 |
Correct |
871 ms |
2136 KB |
Output is correct |
6 |
Correct |
893 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
25 ms |
1884 KB |
Output is correct |
4 |
Correct |
47 ms |
1880 KB |
Output is correct |
5 |
Correct |
434 ms |
1880 KB |
Output is correct |
6 |
Correct |
427 ms |
1884 KB |
Output is correct |
7 |
Correct |
456 ms |
1884 KB |
Output is correct |
8 |
Correct |
441 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1884 KB |
Output is correct |
10 |
Correct |
3 ms |
1884 KB |
Output is correct |
11 |
Correct |
27 ms |
1884 KB |
Output is correct |
12 |
Correct |
36 ms |
1884 KB |
Output is correct |
13 |
Correct |
216 ms |
1880 KB |
Output is correct |
14 |
Correct |
227 ms |
1880 KB |
Output is correct |
15 |
Correct |
461 ms |
2088 KB |
Output is correct |
16 |
Correct |
511 ms |
1884 KB |
Output is correct |
17 |
Correct |
453 ms |
1880 KB |
Output is correct |
18 |
Correct |
8 ms |
1884 KB |
Output is correct |
19 |
Correct |
9 ms |
1884 KB |
Output is correct |
20 |
Correct |
58 ms |
1884 KB |
Output is correct |
21 |
Correct |
49 ms |
1884 KB |
Output is correct |
22 |
Correct |
93 ms |
1880 KB |
Output is correct |
23 |
Correct |
84 ms |
1984 KB |
Output is correct |
24 |
Correct |
117 ms |
2000 KB |
Output is correct |
25 |
Correct |
115 ms |
1880 KB |
Output is correct |
26 |
Correct |
5 ms |
1880 KB |
Output is correct |
27 |
Correct |
5 ms |
1884 KB |
Output is correct |
28 |
Correct |
364 ms |
1884 KB |
Output is correct |
29 |
Correct |
448 ms |
1880 KB |
Output is correct |
30 |
Correct |
879 ms |
2136 KB |
Output is correct |
31 |
Correct |
902 ms |
2152 KB |
Output is correct |
32 |
Correct |
879 ms |
2136 KB |
Output is correct |
33 |
Correct |
897 ms |
2148 KB |
Output is correct |
34 |
Correct |
3 ms |
1880 KB |
Output is correct |
35 |
Correct |
36 ms |
1884 KB |
Output is correct |
36 |
Correct |
180 ms |
1880 KB |
Output is correct |
37 |
Correct |
459 ms |
1884 KB |
Output is correct |
38 |
Correct |
871 ms |
2136 KB |
Output is correct |
39 |
Correct |
893 ms |
2140 KB |
Output is correct |
40 |
Correct |
228 ms |
1880 KB |
Output is correct |
41 |
Correct |
426 ms |
2064 KB |
Output is correct |
42 |
Correct |
732 ms |
2136 KB |
Output is correct |
43 |
Correct |
941 ms |
2140 KB |
Output is correct |
44 |
Correct |
877 ms |
2160 KB |
Output is correct |
45 |
Correct |
899 ms |
2140 KB |
Output is correct |
46 |
Correct |
469 ms |
2132 KB |
Output is correct |
47 |
Correct |
700 ms |
2392 KB |
Output is correct |
48 |
Correct |
674 ms |
2136 KB |
Output is correct |