# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1039798 |
2024-07-31T09:23:05 Z |
juicy |
Two Dishes (JOI19_dishes) |
C++17 |
|
223 ms |
27260 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e6 + 5;
const long long inf = 1e18;
int n, m;
int p[N], q[N];
long long s[N], t[N], a[N], b[N], dp[4 * N], lz[4 * N];
void app(int id, long long x) {
dp[id] += x;
lz[id] += x;
}
void psh(int id) {
if (lz[id]) {
app(id * 2, lz[id]);
app(id * 2 + 1, lz[id]);
lz[id] = 0;
}
if (dp[id]) {
dp[id * 2] = max(dp[id * 2], dp[id]);
dp[id * 2 + 1] = max(dp[id * 2 + 1], dp[id]);
dp[id] = 0;
}
}
void upd(int u, int v, long long x, int id = 1, int l = 0, int r = m) {
if (u <= l && r <= v) {
app(id, x);
return;
}
psh(id);
int md = (l + r) / 2;
if (u <= md) {
upd(u, v, x, id * 2, l, md);
}
if (md < v) {
upd(u, v, x, id * 2 + 1, md + 1, r);
}
}
void add(int u, int v, long long x, int id = 1, int l = 0, int r = m) {
if (u <= l && r <= v) {
dp[id] = max(dp[id], x);
return;
}
psh(id);
int md = (l + r) / 2;
if (u <= md) {
add(u, v, x, id * 2, l, md);
}
if (md < v) {
add(u, v, x, id * 2 + 1, md + 1, r);
}
}
long long qry(int i, int id = 1, int l = 0, int r = m) {
if (l == r) {
return dp[id];
}
psh(id);
int md = (l + r) / 2;
if (i <= md) {
return qry(i, id * 2, l, md);
}
return qry(i, id * 2 + 1, md + 1, r);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> s[i] >> p[i];
a[i] += a[i - 1];
}
for (int i = 1; i <= m; ++i) {
cin >> b[i] >> t[i] >> q[i];
b[i] += b[i - 1];
}
vector<array<int, 3>> cands;
long long sum = 0;
for (int i = 1; i <= n; ++i) {
int j = upper_bound(b, b + m + 1, s[i] - a[i]) - b;
if (j) {
cands.push_back({i, 1 - j, p[i]});
}
}
for (int j = 1; j <= m; ++j) {
int i = upper_bound(a, a + n + 1, t[j] - b[j]) - a;
if (i) {
cands.push_back({i, 1 - j, -q[j]});
sum += q[j];
}
}
sort(cands.begin(), cands.end());
for (auto [x, y, v] : cands) {
y = -y;
upd(0, y, v);
add(y, m, qry(y));
}
cout << sum + qry(m);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
223 ms |
27260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
223 ms |
27260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
223 ms |
27260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |