# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132006 | ekrem | Two Dishes (JOI19_dishes) | C++98 | 201 ms | 26400 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 st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 100000000000000009
#define N 1000005
using namespace std;
typedef long long ll;
typedef pair < ll , ll > ii;
ll n, m, nn, mm, ans, a[2][N], b[2][N], c[2][N], pre[2][N];
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%lld %lld",&n ,&m);
for(ll i = 1; i <= n; i++){
scanf("%lld %lld %lld",&a[0][i] ,&b[0][i] ,&c[0][i]);
pre[0][i] = pre[0][i - 1] + a[0][i];
}
for(ll i = 1; i <= m; i++){
scanf("%lld %lld %lld",&a[1][i] ,&b[1][i] ,&c[1][i]);
pre[1][i] = pre[1][i - 1] + a[1][i];
}
c[0][0] = c[1][0] = inf;
nn = n;mm = m;
for(ll i = 1; i <= n + m; i++){
ll x = (pre[0][nn] + pre[1][mm] <= b[0][nn])?c[0][nn]:-c[0][nn];
ll y = (pre[0][nn] + pre[1][mm] <= b[1][mm])?c[1][mm]:-c[1][mm];
if(x > y){
ans += max(0ll, x);
nn--;
} else{
ans += max(0ll, y);
mm--;
}
}
printf("%lld\n", ans);
return 0;
}
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... |