#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define endl '\n'
#define int ll
using namespace std;
struct node
{
int c, f, v;
};
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N;
vector<node> pc(N);
for (int i = 0; i < N; i++)
{
int c, f, v;
cin >> c >> f >> v;
pc[i] = {c, f, v};
}
cin >> M;
vector<node> qr(M);
for (int i = 0; i < M; i++)
{
int c, f, v;
cin >> c >> f >> v;
qr[i] = {c, f, v};
}
sort(pc.begin(), pc.end(), [&](node &a, node &b)
{ return a.f > b.f; });
sort(qr.begin(), qr.end(), [&](node &a, node &b)
{ return a.f > b.f; });
int dp[M + 1][N + 1];
memset(dp, 0, sizeof dp);
int mx = 0;
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++)
{
// skip zakazku
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
mx = max(mx, dp[i + 1][j]);
// skip pc
dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
mx = max(mx, dp[i][j + 1]);
// take next
if (qr[i].f <= pc[j].f)
{
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (qr[i].v - pc[j].v));
mx = max(mx, dp[i + 1][j + 1]);
}
}
cout << mx << endl;
}
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
2 ms |
1504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |