Submission #344593

# Submission time Handle Problem Language Result Execution time Memory
344593 2021-01-06T06:23:35 Z bachaquer Divide and conquer (IZhO14_divide) C++14
17 / 100
1 ms 364 KB
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
 
using namespace std;
 
ll n, x, g, d;
 
struct lol {
    ll x;
    ll g;
    ll d;
};
 
int main() {
    //freopen("stdin", "r", stdin);
    //freopen("stdout", "w", stdout);
    cin >> n;
    vector<lol> v;
    unsigned long long mx = 0;
    unsigned long long sum = 0;
    ll last = 0;
    for (int i = 0; i < n; i++) {
        cin >> x >> g >> d;
        v.pb({x, g, d});
        if (i == 0 || v[i - 1].d + v[i].d < (v[i].x - v[i - 1].x)) {
            sum = 0;
            if (i != 0 && last + v[i].d >= (v[i].x - v[i - 1].x)) {
                sum += v[i - 1].g;
                last -= (v[i].x - v[i - 1].x);
                if (last < 0) {
                    v[i].d += last;
                }
            }
        }
        else {
            v[i - 1].d -= (v[i].x - v[i - 1].x);
            if (v[i - 1].d < 0) {
                v[i].d += v[i - 1].d;
                v[i - 1].d = 0;
            }
        }
        last = d;
        sum += v[i].g;
        if (sum > mx) mx = sum;
    }
    cout << mx;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -