Submission #441187

# Submission time Handle Problem Language Result Execution time Memory
441187 2021-07-04T14:04:01 Z zxcvbnm Divide and conquer (IZhO14_divide) C++14
100 / 100
48 ms 9416 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct S {
    ll x, g, e;
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<S> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].g >> a[i].e;
    }
    vector<S> pref(n+1, {0, 0, 0});
    for(int i = 1; i <= n; i++) {
        pref[i] = {a[i-1].x, pref[i-1].g+a[i-1].g, pref[i-1].e+a[i-1].e};
    }

//    ll ans = 0;
//    for(int i = 1; i <= n; i++) {
//        for(int j = i; j <= n; j++) {
////            cout << i << " " << j << " " << pref[j].x-pref[i-1].x << " " << pref[j].e-pref[i-1].e << " " << pref[j].g-pref[i-1].g << "\n";
//            if (pref[j].x-pref[i].x <= pref[j].e-pref[i-1].e) {
//                ans = max(ans, pref[j].g-pref[i-1].g);
//            }
//        }
//    }

    ll ans = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    int l = 1;
    for(int i = 1; i <= n; i++) {
        if (pref[i].x-pref[l].x <= pref[i].e-pref[l-1].e) {
            ans = max(ans, pref[i].g-pref[l-1].g);
        } else {
            ll need = (pref[i].x-pref[l].x) - (pref[i].e-pref[l-1].e);
            q.push({need, i});
        }
    }
    ll delta = 0;
    for(int i = 2; i <= n; i++) {
        ll lose = a[i-2].e;
        ll gain = a[i-1].x - a[i-2].x;
        delta += gain - lose;
        while(!q.empty()) {
            auto v = q.top();
            if (v.first <= delta) {
                q.pop();
                ans = max(ans, pref[v.second].g - pref[i-1].g);
            } else {
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 4 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 4 ms 800 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 5 ms 716 KB Output is correct
28 Correct 18 ms 2636 KB Output is correct
29 Correct 20 ms 3916 KB Output is correct
30 Correct 40 ms 7888 KB Output is correct
31 Correct 34 ms 6624 KB Output is correct
32 Correct 35 ms 6736 KB Output is correct
33 Correct 34 ms 6612 KB Output is correct
34 Correct 46 ms 8768 KB Output is correct
35 Correct 45 ms 9312 KB Output is correct
36 Correct 48 ms 9416 KB Output is correct