| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 384665 | zoooma13 | 금 캐기 (IZhO14_divide) | C++14 | 0 ms | 0 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>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    vector <array<int64_t ,3>> a(n);
    int64_t ans;
    for(auto&x : a)
        scanf("%lld%lld%lld",&x[0],&x[1],&x[2]) ,ans = max(ans ,x[2]);
    set <pair<int ,int>> ss;
    a.insert(a.begin() ,{0,0,0});
    for(int i=1; i<=n; i++){
        a[i][1] += a[i-1][1];
        a[i][2] += a[i-1][2];
        auto it = ss.upper_bound({a[i][2] - a[i][0] ,0});
        if(it != ss.begin()){
            it = prev(it);
            ans = max(ans ,a[i][1] - it->second);
        }
        auto it = ss.insert({a[i-1][2] + a[i][0] ,a[i-1][1]}).first;
        if(it == ss.begin() || prev(it)->second > it->second){
            while(next(it) != ss.end() && next(it)->second >= it->second)
                ss.erase(next(it));
        }else{
            ss.erase(it);
        }
        ///a[i][2] - a[i][0] >= a[j][2] + a[j][0]
    }
    printf("%lld\n",ans);
}
