#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1LL<<60;
const ll mxc=21000;
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/4)
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
6 ms |
632 KB |
Output is correct |
4 |
Correct |
9 ms |
632 KB |
Output is correct |
5 |
Correct |
64 ms |
888 KB |
Output is correct |
6 |
Correct |
64 ms |
732 KB |
Output is correct |
7 |
Correct |
69 ms |
632 KB |
Output is correct |
8 |
Correct |
68 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
6 ms |
632 KB |
Output is correct |
4 |
Correct |
6 ms |
632 KB |
Output is correct |
5 |
Correct |
33 ms |
636 KB |
Output is correct |
6 |
Correct |
31 ms |
632 KB |
Output is correct |
7 |
Correct |
74 ms |
760 KB |
Output is correct |
8 |
Correct |
69 ms |
780 KB |
Output is correct |
9 |
Correct |
69 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
8 ms |
632 KB |
Output is correct |
4 |
Correct |
8 ms |
632 KB |
Output is correct |
5 |
Correct |
14 ms |
636 KB |
Output is correct |
6 |
Correct |
14 ms |
632 KB |
Output is correct |
7 |
Correct |
18 ms |
632 KB |
Output is correct |
8 |
Correct |
18 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
51 ms |
760 KB |
Output is correct |
4 |
Correct |
60 ms |
764 KB |
Output is correct |
5 |
Incorrect |
136 ms |
760 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
7 ms |
636 KB |
Output is correct |
3 |
Correct |
29 ms |
632 KB |
Output is correct |
4 |
Correct |
65 ms |
632 KB |
Output is correct |
5 |
Correct |
141 ms |
760 KB |
Output is correct |
6 |
Incorrect |
146 ms |
760 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
6 ms |
632 KB |
Output is correct |
4 |
Correct |
9 ms |
632 KB |
Output is correct |
5 |
Correct |
64 ms |
888 KB |
Output is correct |
6 |
Correct |
64 ms |
732 KB |
Output is correct |
7 |
Correct |
69 ms |
632 KB |
Output is correct |
8 |
Correct |
68 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
632 KB |
Output is correct |
11 |
Correct |
6 ms |
632 KB |
Output is correct |
12 |
Correct |
6 ms |
632 KB |
Output is correct |
13 |
Correct |
33 ms |
636 KB |
Output is correct |
14 |
Correct |
31 ms |
632 KB |
Output is correct |
15 |
Correct |
74 ms |
760 KB |
Output is correct |
16 |
Correct |
69 ms |
780 KB |
Output is correct |
17 |
Correct |
69 ms |
760 KB |
Output is correct |
18 |
Correct |
3 ms |
632 KB |
Output is correct |
19 |
Correct |
3 ms |
632 KB |
Output is correct |
20 |
Correct |
8 ms |
632 KB |
Output is correct |
21 |
Correct |
8 ms |
632 KB |
Output is correct |
22 |
Correct |
14 ms |
636 KB |
Output is correct |
23 |
Correct |
14 ms |
632 KB |
Output is correct |
24 |
Correct |
18 ms |
632 KB |
Output is correct |
25 |
Correct |
18 ms |
632 KB |
Output is correct |
26 |
Correct |
3 ms |
632 KB |
Output is correct |
27 |
Correct |
3 ms |
632 KB |
Output is correct |
28 |
Correct |
51 ms |
760 KB |
Output is correct |
29 |
Correct |
60 ms |
764 KB |
Output is correct |
30 |
Incorrect |
136 ms |
760 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |