#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 998244353;
ld fpow(ll a, ll b, ll m = -1)
{
if (m != -1)
a %= m;
ll res = 1;
while (b > 0)
{
if (b % 2 == 1)
{
if (m != -1)
res = res * a % m;
else
{
res *= a;
}
}
a = a * a;
if (m != -1)
{
a %= m;
}
b /= 2;
}
return res;
}
vector<vector<char>> v;
vector<vector<ll>> a;
ll n, m;
void dfs(ll i, ll j, ll k)
{
if (i < 0 || i >= n || j < 0 || j >= m || a[i][j] || v[i][j] == '.')
{
return;
}
a[i][j] = k;
dfs(i + 1, j, k), dfs(i - 1, j, k), dfs(i, j + 1, k), dfs(i, j - 1, k);
}
int main()
{
fast;
// freopen("pails.in", "r", stdin);
// freopen("pails.out", "w", stdout);
ll t = 1;
// cin >> t;
while (t--)
{
ll n, m;
cin >> n;
vector<array<ll, 3>> a(n);
ll s1 = 0, s2 = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i][1] >> a[i][0] >> a[i][2];
s1 += a[i][1];
}
sort(all(a), greater<array<ll, 3>>());
cin >> m;
vector<array<ll, 3>> b(m);
for (int i = 0; i < m; i++)
{
cin >> b[i][1] >> b[i][0] >> b[i][2];
s2 += b[i][1];
}
sort(all(b), greater<>());
vector<ll> dp(max(s2, s1) + 1, LLONG_MIN/4);
ll in = 0;
dp[0]=0;
for (int i = 0; i < m; i++)
{
while (in < n && b[i][0] <= a[in][0])
{
for (int j = dp.size() - 1; j >= a[in][1]; j--)
{
dp[j] = max(dp[j], dp[j - a[in][1]] - a[in][2]);
}
in++;
}
for (int j = 0; j < dp.size()-b[i][1]; j++)
{
dp[j] = max(dp[j], dp[j + b[i][1]] + b[i][2]);
}
}
// for(int i = 0; i < dp.size())
cout << *max_element(all(dp)) << '\n';
}
return 0;
}
Compilation message
clo.cpp: In function 'int main()':
clo.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
91 | for (int j = 0; j < dp.size()-b[i][1]; j++)
# |
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 |
74 ms |
788 KB |
Output is correct |
6 |
Correct |
25 ms |
604 KB |
Output is correct |
7 |
Correct |
151 ms |
1112 KB |
Output is correct |
8 |
Correct |
141 ms |
1116 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
496 KB |
Output is correct |
7 |
Correct |
76 ms |
804 KB |
Output is correct |
8 |
Correct |
17 ms |
604 KB |
Output is correct |
9 |
Correct |
148 ms |
1116 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
468 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 |
6 ms |
348 KB |
Output is correct |
4 |
Correct |
15 ms |
588 KB |
Output is correct |
5 |
Correct |
161 ms |
860 KB |
Output is correct |
6 |
Correct |
297 ms |
1112 KB |
Output is correct |
7 |
Correct |
294 ms |
1112 KB |
Output is correct |
8 |
Correct |
287 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
18 ms |
604 KB |
Output is correct |
4 |
Correct |
5 ms |
548 KB |
Output is correct |
5 |
Correct |
299 ms |
1116 KB |
Output is correct |
6 |
Correct |
308 ms |
1112 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 |
74 ms |
788 KB |
Output is correct |
6 |
Correct |
25 ms |
604 KB |
Output is correct |
7 |
Correct |
151 ms |
1112 KB |
Output is correct |
8 |
Correct |
141 ms |
1116 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
18 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
496 KB |
Output is correct |
15 |
Correct |
76 ms |
804 KB |
Output is correct |
16 |
Correct |
17 ms |
604 KB |
Output is correct |
17 |
Correct |
148 ms |
1116 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
452 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
468 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 |
6 ms |
348 KB |
Output is correct |
29 |
Correct |
15 ms |
588 KB |
Output is correct |
30 |
Correct |
161 ms |
860 KB |
Output is correct |
31 |
Correct |
297 ms |
1112 KB |
Output is correct |
32 |
Correct |
294 ms |
1112 KB |
Output is correct |
33 |
Correct |
287 ms |
1112 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
18 ms |
604 KB |
Output is correct |
37 |
Correct |
5 ms |
548 KB |
Output is correct |
38 |
Correct |
299 ms |
1116 KB |
Output is correct |
39 |
Correct |
308 ms |
1112 KB |
Output is correct |
40 |
Correct |
20 ms |
604 KB |
Output is correct |
41 |
Correct |
85 ms |
860 KB |
Output is correct |
42 |
Correct |
5 ms |
348 KB |
Output is correct |
43 |
Correct |
327 ms |
1372 KB |
Output is correct |
44 |
Correct |
327 ms |
1368 KB |
Output is correct |
45 |
Correct |
324 ms |
1368 KB |
Output is correct |
46 |
Correct |
2 ms |
536 KB |
Output is correct |
47 |
Correct |
7 ms |
348 KB |
Output is correct |
48 |
Correct |
4 ms |
348 KB |
Output is correct |