#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
struct event {
int c, f, v, flag;
} items[5010];
const int INF = 1e18, lim = 10000;
int N, M, st, ans = 0;
int dp[10010];
signed main() {
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> items[i].c >> items[i].f >> items[i].v;
items[i].flag = 1;
}
cin >> M;
for (int i = N + 1; i <= N + M; ++i) {
cin >> items[i].c >> items[i].f >> items[i].v;
items[i].flag = 0;
}
sort(items + 1, items + 1 + N + M, [](event a, event b) {
if (a.f == b.f) return a.flag > b.flag;
return a.f > b.f;
});
for (int i = 0; i <= lim; ++i) dp[i] = -INF;
bool skip = true;
for (int i = 1; i <= N + M; ++i) {
if (items[i].flag) skip = false;
if (skip) continue;
vector<int> new_dp(lim, -INF);
for (int j = 0; j <= lim; ++j) {
if (items[i].flag) {
if (j == items[i].c) new_dp[j] = max(dp[j], -items[i].v);
else if (j > items[i].c) new_dp[j] = max(dp[j], dp[j - items[i].c] - items[i].v);
else new_dp[j] = dp[j];
} else {
new_dp[j] = dp[j];
if (j + items[i].c <= lim) new_dp[j] = max(new_dp[j], dp[j + items[i].c] + items[i].v);
ans = max(ans, new_dp[j]);
}
}
for (int j = 0; j <= lim; ++j) dp[j] = new_dp[j];
}
cout << ans;
return 0;
}
Compilation message
clo.cpp: In function 'int main()':
clo.cpp:57:46: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset [80000, 80007] is out of the bounds [0, 80000] [-Warray-bounds]
57 | for (int j = 0; j <= lim; ++j) dp[j] = new_dp[j];
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
388 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Incorrect |
45 ms |
540 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
596 KB |
Output is correct |
6 |
Incorrect |
16 ms |
508 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
30 ms |
468 KB |
Output is correct |
4 |
Correct |
60 ms |
496 KB |
Output is correct |
5 |
Incorrect |
78 ms |
560 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
476 KB |
Output is correct |
4 |
Correct |
46 ms |
524 KB |
Output is correct |
5 |
Correct |
89 ms |
632 KB |
Output is correct |
6 |
Incorrect |
103 ms |
596 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
388 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Incorrect |
45 ms |
540 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |