This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 2010;
long long a[N], b[N], s[N], t[N], p[N], q[N];
vector<int> event[N];
int n, m;
long long T[N << 2], lazy[N << 2];
void push(int s, int l, int r) {
if (lazy[s] == 0) return;
T[s] += lazy[s];
if (l != r) {
lazy[s << 1] += lazy[s];
lazy[s << 1 | 1] += lazy[s];
}
lazy[s] = 0;
}
void up(int s, int l, int r, int from, int to, long long val, bool type) {
push(s, l, r);
if (l > to || r < from) return;
if (from <= l && r <= to) {
if (type) {
T[s] = max(T[s], val);
}
else {
lazy[s] += val;
push(s, l, r);
}
return;
}
int mid = l + r >> 1;
up(s << 1, l, mid, from, to, val, type);
up(s << 1 | 1, mid + 1, r, from, to, val, type);
T[s] = max(T[s << 1], T[s << 1 | 1]);
}
long long get(int s, int l, int r, int from, int to) {
push(s, l, r);
if (l > to || r < from) return -1e18;
if (from <= l && r <= to) return T[s];
int mid = l + r >> 1;
return max(get(s << 1, l, mid, from, to), get(s << 1 | 1, mid + 1, r, from, to));
}
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> s[i] >> p[i];
p[i] = p[i];
a[i] += a[i - 1];
}
for(int i = 1; i <= m; i++) {
cin >> b[i] >> t[i] >> q[i];
q[i] = q[i];
b[i] += b[i - 1];
}
for(int i = 1; i <= n; i++) {
int l = 0, r = m, last = -1;
while (l <= r) {
int mid = l + r >> 1;
if (a[i] + b[mid] <= s[i]) {
last = mid;
l = mid + 1;
}
else r = mid - 1;
}
s[i] = last;
}
for(int i = 1; i <= m; i++) {
int l = 0, r = n, last = -1;
while (l <= r) {
int mid = l + r >> 1;
if (b[i] + a[mid] <= t[i]) {
last = mid;
l = mid + 1;
}
else r = mid - 1;
}
t[i] = last;
if (last >= 0) {
event[last].push_back(i);
}
}
// for(int i = 1; i <= n; i++) cout << s[i] << " "; cout << endl;
// for(int i = 1; i <= m; i++) cout << t[i] << " "; cout << endl;
for(int i = 1; i <= 4 * (m + 1); i++) T[i] = -1e18;
up(1, 0, m, 0, 0, 0, 1);
for(int i = 1; i <= n + 1; i++) {
for(int &j : event[i - 1]) {
long long f = get(1, 0, m, 0, j - 1);
up(1, 0, m, j, j, f, 1);
}
long long f = get(1, 0, m, 0, s[i]);
up(1, 0, m, s[i] + 1, s[i] + 1, f, 1);
up(1, 0, m, 0, s[i], p[i], 0);
for(int &j : event[i - 1]) {
up(1, 0, m, j, m, q[j], 0);
}
}
cout << get(1, 0, m, 1, m);
}
Compilation message (stderr)
dishes.cpp: In function 'void up(int, int, int, int, int, long long int, bool)':
dishes.cpp:35:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int mid = l + r >> 1;
| ~~^~~
dishes.cpp: In function 'long long int get(int, int, int, int, int)':
dishes.cpp:45:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
45 | int mid = l + r >> 1;
| ~~^~~
dishes.cpp: In function 'int main()':
dishes.cpp:75:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
75 | int mid = l + r >> 1;
| ~~^~~
dishes.cpp:87:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
87 | int mid = l + r >> 1;
| ~~^~~
dishes.cpp:54:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | freopen ("task.inp", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:55:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen ("task.out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:58:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen (task".inp", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:59:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen (task".out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |