# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259117 | patrikpavic2 | Two Dishes (JOI19_dishes) | C++17 | 227 ms | 51944 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 <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 1e6 + 500;
const ll INF = 1e18;
ll del[N], mora[N];
int n, m;
int S[N], T[N], Q[N], P[N], A[N], B[N];
int SS[N], TT[N];
vector < ll > v, v2;
vector < int > brisi[N];
int main(){
scanf("%d%d", &n, &m);
for(int i = 1;i <= n;i++)
scanf("%d%d%d", A + i, S + i, P + i);
for(int i = 1;i <= m;i++)
scanf("%d%d%d", B + i, T + i, Q + i);
ll cur = 0; v.PB(cur);
for(int i = 1;i <= m;i++)
cur += B[i], v.PB(cur);
cur = 0; v2.PB(cur);
for(int i = 1;i <= n;i++){
cur += A[i]; v2.PB(cur);
if(S[i] < cur)
P[i] = 0, S[i] = cur;
SS[i] = upper_bound(v.begin(), v.end(), S[i] - cur) - v.begin() - 1;
}
cur = 0;
for(int i = 1;i <= m;i++){
cur += B[i];
if(T[i] < cur)
Q[i] = 0, T[i] = cur;
TT[i] = upper_bound(v2.begin(), v2.end(), T[i] - cur) - v2.begin() - 1;
}
for(int i = 1;i <= m;i++){
del[i] = Q[i], mora[i] = Q[i];
brisi[SS[i]].PB(i);
}
for(int i = 1;i <= n;i++){
del[0] += P[i];
del[TT[i] + 1] = max(del[TT[i] + 1] - P[i], mora[TT[i] + 1]);
for(int j : brisi[i])
mora[j] = -INF;
}
ll ans = 0;
for(int i = 0;i <= m;i++)
ans += del[i];
printf("%lld\n", ans);
}
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... |