#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
typedef long double ld;
int N, M, f, c, v, idx1, idx2, dp[100005];
vector<tuple<int, int, int> > F, S;
vector<pair<int, bool> > V;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1, c, f, v; i <= N; i++) {
cin >> c >> f >> v;
F.eb(-f, c, v);
}
cin >> M;
for (int i = 1; i <= M; i++) {
cin >> c >> f >> v;
S.eb(-f, c, v);
}
sort(F.begin(), F.end());
sort(S.begin(), S.end());
while (idx1 < F.size() && idx2 < S.size())
if (get<0>(F[idx1]) < get<0>(S[idx2])) V.eb(idx1++, 0);
else V.eb(idx2++, 1);
while (idx1 < F.size()) V.eb(idx1++, 0);
while (idx2 < S.size()) V.eb(idx2++, 1);
for (int i = N + M - 1; i >= 0; i--) {
if (V[i].second)
for (int j = 100000; j >= get<1>(S[V[i].first]); j--)
dp[j] = max(dp[j], dp[j - get<1>(S[V[i].first])] + get<2>(S[V[i].first]));
else
for (int j = 0; j <= 100000 - get<1>(F[V[i].first]); j++)
dp[j] = max(dp[j], dp[j + get<1>(F[V[i].first])] - get<2>(F[V[i].first]));
}
cout << dp[0] << '\n';
}
Compilation message
clo.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
clo.cpp: In function 'int main()':
clo.cpp:30:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (idx1 < F.size() && idx2 < S.size())
~~~~~^~~~~~~~~~
clo.cpp:30:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (idx1 < F.size() && idx2 < S.size())
~~~~~^~~~~~~~~~
clo.cpp:33:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (idx1 < F.size()) V.eb(idx1++, 0);
~~~~~^~~~~~~~~~
clo.cpp:34:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (idx2 < S.size()) V.eb(idx2++, 1);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
26 ms |
1152 KB |
Output is correct |
4 |
Correct |
45 ms |
1152 KB |
Output is correct |
5 |
Correct |
369 ms |
1280 KB |
Output is correct |
6 |
Correct |
384 ms |
1400 KB |
Output is correct |
7 |
Correct |
417 ms |
1292 KB |
Output is correct |
8 |
Correct |
401 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
7 ms |
1152 KB |
Output is correct |
3 |
Correct |
25 ms |
1152 KB |
Output is correct |
4 |
Correct |
29 ms |
1152 KB |
Output is correct |
5 |
Correct |
194 ms |
1272 KB |
Output is correct |
6 |
Correct |
187 ms |
1152 KB |
Output is correct |
7 |
Correct |
420 ms |
1280 KB |
Output is correct |
8 |
Correct |
402 ms |
1404 KB |
Output is correct |
9 |
Incorrect |
393 ms |
1280 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1152 KB |
Output is correct |
2 |
Correct |
12 ms |
1152 KB |
Output is correct |
3 |
Correct |
39 ms |
1152 KB |
Output is correct |
4 |
Correct |
40 ms |
1024 KB |
Output is correct |
5 |
Correct |
77 ms |
1152 KB |
Output is correct |
6 |
Correct |
77 ms |
1152 KB |
Output is correct |
7 |
Correct |
112 ms |
1272 KB |
Output is correct |
8 |
Correct |
108 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
1152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
35 ms |
1152 KB |
Output is correct |
3 |
Correct |
174 ms |
1152 KB |
Output is correct |
4 |
Correct |
391 ms |
1280 KB |
Output is correct |
5 |
Correct |
786 ms |
1528 KB |
Output is correct |
6 |
Correct |
819 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
26 ms |
1152 KB |
Output is correct |
4 |
Correct |
45 ms |
1152 KB |
Output is correct |
5 |
Correct |
369 ms |
1280 KB |
Output is correct |
6 |
Correct |
384 ms |
1400 KB |
Output is correct |
7 |
Correct |
417 ms |
1292 KB |
Output is correct |
8 |
Correct |
401 ms |
1400 KB |
Output is correct |
9 |
Correct |
6 ms |
1152 KB |
Output is correct |
10 |
Correct |
7 ms |
1152 KB |
Output is correct |
11 |
Correct |
25 ms |
1152 KB |
Output is correct |
12 |
Correct |
29 ms |
1152 KB |
Output is correct |
13 |
Correct |
194 ms |
1272 KB |
Output is correct |
14 |
Correct |
187 ms |
1152 KB |
Output is correct |
15 |
Correct |
420 ms |
1280 KB |
Output is correct |
16 |
Correct |
402 ms |
1404 KB |
Output is correct |
17 |
Incorrect |
393 ms |
1280 KB |
Output isn't correct |