/*raghav0307 - Raghav Gupta*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define int ll
struct Item{
int c, f, v, prod;
Item (int c_, int f_, int v_, int prod_) :
c(c_), f(f_), v(v_), prod(prod_) {}
};
bool custom(Item a, Item b){
if(a.f < b.f)
return false;
if(a.f > b.f)
return true;
return a.prod < b.prod;
}
const int inf = 1e15;
vector<Item> v;
vector<int> dp;
signed main(){
fast_io();
int n; cin >> n;
int tCores = 0;
for(int i = 0; i < n; i++){
int c, f, vv;
cin >> c >> f >> vv;
v.push_back(Item(c, f, vv, 1));
tCores += c;
}
int m; cin >> m;
for(int i = 0; i < m; i++){
int c, f, vv;
cin >> c >> f >> vv;
v.push_back(Item(c, f, vv, 2));
}
sort(v.begin(), v.end(), custom);
dp.resize(tCores + 1, -inf);
dp[0] = 0ll;
for(auto &x : v){
if(x.prod == 1){
for(int i = tCores - x.c; i >= 0; i--){
dp[i + x.c] = max(dp[i + x.c], dp[i] - x.v);
}
}
else if(x.prod == 2){
for(int i = x.c; i <= tCores; i++){
dp[i - x.c] = max(dp[i-x.c], dp[i] + x.v);
}
}
}
int ans = 0;
for(auto x : dp)
ans = max(ans, x);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
524 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
28 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
124 ms |
896 KB |
Output is correct |
8 |
Correct |
28 ms |
640 KB |
Output is correct |
9 |
Correct |
193 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
245 ms |
1024 KB |
Output is correct |
6 |
Correct |
436 ms |
1408 KB |
Output is correct |
7 |
Correct |
435 ms |
1408 KB |
Output is correct |
8 |
Correct |
410 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
412 KB |
Output is correct |
3 |
Correct |
27 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
496 KB |
Output is correct |
5 |
Correct |
429 ms |
1280 KB |
Output is correct |
6 |
Correct |
503 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
524 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
28 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
124 ms |
896 KB |
Output is correct |
16 |
Correct |
28 ms |
640 KB |
Output is correct |
17 |
Correct |
193 ms |
1152 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
10 ms |
512 KB |
Output is correct |
29 |
Correct |
4 ms |
512 KB |
Output is correct |
30 |
Correct |
245 ms |
1024 KB |
Output is correct |
31 |
Correct |
436 ms |
1408 KB |
Output is correct |
32 |
Correct |
435 ms |
1408 KB |
Output is correct |
33 |
Correct |
410 ms |
1280 KB |
Output is correct |
34 |
Correct |
2 ms |
256 KB |
Output is correct |
35 |
Correct |
3 ms |
412 KB |
Output is correct |
36 |
Correct |
27 ms |
512 KB |
Output is correct |
37 |
Correct |
7 ms |
496 KB |
Output is correct |
38 |
Correct |
429 ms |
1280 KB |
Output is correct |
39 |
Correct |
503 ms |
1280 KB |
Output is correct |
40 |
Correct |
32 ms |
640 KB |
Output is correct |
41 |
Correct |
84 ms |
768 KB |
Output is correct |
42 |
Correct |
9 ms |
640 KB |
Output is correct |
43 |
Correct |
486 ms |
1408 KB |
Output is correct |
44 |
Correct |
537 ms |
1408 KB |
Output is correct |
45 |
Correct |
485 ms |
1408 KB |
Output is correct |
46 |
Correct |
6 ms |
512 KB |
Output is correct |
47 |
Correct |
9 ms |
640 KB |
Output is correct |
48 |
Correct |
8 ms |
512 KB |
Output is correct |