#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;
const int mod = 1e9 + 7;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<array<int, 4> > w;
for(int i = 0;i < n; i++){
int c, f, cost; cin >> c >> f >> cost;
w.push_back({c, f, cost, 1});
}
int m; cin >> m;
for(int i = 0;i < m; i++){
int c, f, cost; cin >> c >> f >> cost;
w.push_back({c, f, cost, 0});
}
sort(all(w), [&](auto A, auto B){
if(A[1] == B[1]) return A[3] > B[3];
return A[1] > B[1];
});
vector<int> dp(N+5, -mod);
dp[0] = 0;
for(auto [c, f, cost, type] : w){
if(type == 1){
for(int i = N; i >= c; i--){
dp[i] = max(dp[i], dp[i-c] - cost);
}
}else{
for(int i = 1; i <= N - c; i++){
dp[i] = max(dp[i], dp[i+c] + cost);
}
}
}
cout << *max_element(all(dp));
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Incorrect |
17 ms |
1116 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
16 ms |
1116 KB |
Output is correct |
4 |
Incorrect |
19 ms |
1116 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
24 ms |
1116 KB |
Output is correct |
3 |
Correct |
119 ms |
1116 KB |
Output is correct |
4 |
Correct |
297 ms |
1116 KB |
Output is correct |
5 |
Correct |
577 ms |
1372 KB |
Output is correct |
6 |
Correct |
592 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Incorrect |
17 ms |
1116 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |