///*** Sown_Vipro ***///
/// ->GIAI BA QUOC GIA<- ///
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define F first
#define S second
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
#define szz(s) int(s.size())
#define int long long
const int N = 1e5 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7;
int n, m, mx;
long long res;
struct node{
int c, f, v;
} t[N];
long long dp[2][N];
bool cmp(node a, node b){
if(a.f != b.f) return a.f > b.f;
return a.v < b.v;
}
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i){
int c, f, v; cin >> c >> f >> v;
t[i] = {c, f, -v};
mx += c;
}
cin >> m;
for(int i = n + 1; i <= n + m; ++i){
int c, f, v; cin >> c >> f >> v;
t[i] = {-c, f, v};
}
n += m;
sort(t + 1, t + 1 + n, cmp);
for(int C = 1; C <= mx; ++C) dp[0][C] = -1e18;
for(int i = 1; i <= n; ++i){
auto [c, f, v] = t[i];
// cout << c << " " << f << " " << v << "\n";
for(int C = 1; C <= mx; ++C) dp[i % 2][C] = -1e18;
for(int C = mx; C >= 0; --C){
dp[i % 2][C] = dp[1 - (i % 2)][C];
if(C - c >= 0 && C - c <= mx){
dp[i % 2][C] = max(dp[i % 2][C], dp[1 - (i % 2)][C - c] + v);
// cout << C << " " << dp[i % 2][C] << "\n";
res = max(res, dp[i % 2][C]);
}
}
}
cout << res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
inp("in.txt");
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
Compilation message
clo.cpp: In function 'int main()':
clo.cpp:14:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
clo.cpp:66:5: note: in expansion of macro 'inp'
66 | inp("in.txt");
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
49 ms |
860 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
231 ms |
1372 KB |
Output is correct |
8 |
Correct |
44 ms |
600 KB |
Output is correct |
9 |
Correct |
398 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
16 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
428 ms |
1392 KB |
Output is correct |
6 |
Correct |
823 ms |
1880 KB |
Output is correct |
7 |
Correct |
816 ms |
1880 KB |
Output is correct |
8 |
Correct |
750 ms |
1944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
46 ms |
860 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
780 ms |
1884 KB |
Output is correct |
6 |
Correct |
818 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
49 ms |
860 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
231 ms |
1372 KB |
Output is correct |
16 |
Correct |
44 ms |
600 KB |
Output is correct |
17 |
Correct |
398 ms |
1884 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
16 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
428 ms |
1392 KB |
Output is correct |
31 |
Correct |
823 ms |
1880 KB |
Output is correct |
32 |
Correct |
816 ms |
1880 KB |
Output is correct |
33 |
Correct |
750 ms |
1944 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
46 ms |
860 KB |
Output is correct |
37 |
Correct |
9 ms |
344 KB |
Output is correct |
38 |
Correct |
780 ms |
1884 KB |
Output is correct |
39 |
Correct |
818 ms |
1884 KB |
Output is correct |
40 |
Correct |
52 ms |
856 KB |
Output is correct |
41 |
Correct |
148 ms |
860 KB |
Output is correct |
42 |
Correct |
11 ms |
600 KB |
Output is correct |
43 |
Correct |
885 ms |
2152 KB |
Output is correct |
44 |
Correct |
888 ms |
2164 KB |
Output is correct |
45 |
Correct |
876 ms |
2136 KB |
Output is correct |
46 |
Correct |
5 ms |
348 KB |
Output is correct |
47 |
Correct |
11 ms |
604 KB |
Output is correct |
48 |
Correct |
10 ms |
604 KB |
Output is correct |