#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1LL<<60;
const ll mxc=10000;
struct dat {
ll c,f,v;
bool operator<(const dat& masik) const {
if(f==masik.f) return c<masik.c;
return f<masik.f;
}
};
ll dp[2][mxc+1];
int main() {
int n,m;
cin>>n;
vector<dat> lst(n);
for(int i=0;i<n;++i) {
cin>>lst[i].c>>lst[i].f>>lst[i].v;
lst[i].v=-lst[i].v;
}
cin>>m;
lst.resize(n+m);
for(int i=n;i<n+m;++i) {
cin>>lst[i].c>>lst[i].f>>lst[i].v;
lst[i].c=-lst[i].c;
}
sort(lst.begin(),lst.end());
for(auto& i:dp[(n+m)&1]) i=-inf;
dp[(n+m)&1][0]=0;
for(int i=n+m-1;i>=0;i--) {
//cerr<<lst[i].c<<"\n";
for(int j=mxc;j>=0;j--) {
dp[i&1][j]=dp[(i+1)&1][j];
if(j-lst[i].c>=0 && j-lst[i].c<=mxc) {
if(dp[i&1][j]>=-inf/2)
dp[i&1][j]=max(dp[i&1][j], dp[(i+1)&1][j-lst[i].c]+lst[i].v);
else
dp[i&1][j]=dp[(i+1)&1][j-lst[i].c]+lst[i].v;
}
}
//for(int j=0;j<=mxc;++j) cerr<<dp[i][j]<<" \n"[j==mxc];
}
ll ans=-inf;
for(int i=0;i<=mxc;++i) ans=max(ans, dp[0][i]);
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
31 ms |
636 KB |
Output is correct |
6 |
Correct |
32 ms |
504 KB |
Output is correct |
7 |
Correct |
34 ms |
760 KB |
Output is correct |
8 |
Correct |
34 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
508 KB |
Output is correct |
5 |
Correct |
18 ms |
632 KB |
Output is correct |
6 |
Correct |
16 ms |
504 KB |
Output is correct |
7 |
Correct |
38 ms |
760 KB |
Output is correct |
8 |
Correct |
34 ms |
632 KB |
Output is correct |
9 |
Correct |
35 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
4 |
Correct |
6 ms |
504 KB |
Output is correct |
5 |
Correct |
8 ms |
504 KB |
Output is correct |
6 |
Correct |
8 ms |
504 KB |
Output is correct |
7 |
Correct |
10 ms |
536 KB |
Output is correct |
8 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
424 KB |
Output is correct |
3 |
Correct |
25 ms |
632 KB |
Output is correct |
4 |
Correct |
28 ms |
604 KB |
Output is correct |
5 |
Incorrect |
68 ms |
632 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
16 ms |
544 KB |
Output is correct |
4 |
Correct |
32 ms |
504 KB |
Output is correct |
5 |
Correct |
70 ms |
708 KB |
Output is correct |
6 |
Incorrect |
69 ms |
676 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
31 ms |
636 KB |
Output is correct |
6 |
Correct |
32 ms |
504 KB |
Output is correct |
7 |
Correct |
34 ms |
760 KB |
Output is correct |
8 |
Correct |
34 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
508 KB |
Output is correct |
13 |
Correct |
18 ms |
632 KB |
Output is correct |
14 |
Correct |
16 ms |
504 KB |
Output is correct |
15 |
Correct |
38 ms |
760 KB |
Output is correct |
16 |
Correct |
34 ms |
632 KB |
Output is correct |
17 |
Correct |
35 ms |
632 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
508 KB |
Output is correct |
21 |
Correct |
6 ms |
504 KB |
Output is correct |
22 |
Correct |
8 ms |
504 KB |
Output is correct |
23 |
Correct |
8 ms |
504 KB |
Output is correct |
24 |
Correct |
10 ms |
536 KB |
Output is correct |
25 |
Correct |
10 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
424 KB |
Output is correct |
28 |
Correct |
25 ms |
632 KB |
Output is correct |
29 |
Correct |
28 ms |
604 KB |
Output is correct |
30 |
Incorrect |
68 ms |
632 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |