# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768981 | nguyentunglam | Two Dishes (JOI19_dishes) | C++17 | 8 ms | 596 KiB |
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];
long long f[N];
vector<int> event[N];
int n, m;
void up(int j, int x) {
long long sum = 0;
for(int i = j; i >= 1; i--) {
if (x <= t[i]) sum += q[i];
f[j] = max(f[j], f[i - 1] + sum);
}
}
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 <= m; i++) f[i] = -1e9;
for(int i = 1; i <= n; i++) {
for(int &j : event[i - 1]) up(j, i - 1);
up(s[i] + 1, i - 1);
for(int j = 0; j <= s[i]; j++) f[j] += p[i];
// for(int j = 0; j <= m; j++) cout << f[j] << " ";
}
up(m, n);
cout << f[m];
}
Compilation message (stderr)
# | 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... |