Submission #289881

# Submission time Handle Problem Language Result Execution time Memory
289881 2020-09-03T07:52:06 Z MasterTaster Divide and conquer (IZhO14_divide) C++14
0 / 100
1 ms 384 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second
#define endl "\n"

ll n, x[100010], g[100010], e[100010], ress, prefG[100010];
set<pii> s;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>>n;
    for (int i=0; i<n; i++) cin>>x[i]>>g[i]>>e[i];

    prefG[0]=g[0];
    for (int i=1; i<n; i++)
    {
        prefG[i]=prefG[i-1]+g[i];
    }

    ll energy=0, dist=0;
    s.insert({0-x[0], 0});
    ress=max(ress, prefG[0]);
    for (int i=1; i<n; i++)
    {
        if (i) energy+=e[i-1];
        dist=x[i];

        //cout<<energy<<" "<<dist<<endl;
        pair<ll, ll> p;
        auto it=s.upper_bound({energy+e[i]-x[i], 1});
        if (it==s.end())
        {
            //cout<<"ee"<<i<<endl;
            p=*s.rbegin();
        }
        else
        {
            //cout<<"eee"<<i<<endl;
            if (it!=s.begin())
            {
                //cout<<"r"<<i<<endl;
                it--;
                p=*it;
            }
            else
            {
                s.insert({energy-dist, -i});
                continue;
            }
        }


        ll trRess=prefG[i];
        if (-p.yy>0) trRess-=prefG[-p.yy-1];

        ress=max(ress, trRess);

        //cout<<"ubacujem "<<energy-dist<<" "<<-i<<endl;
        s.insert({energy-dist, -i});
    }

    for (int i=0; i<n; i++) ress=max(ress, g[i]);
    /*for (int i=0; i<n; i++)
    {
        ll trGold=0, trEnergy=0, trDist=0;
        for (int j=i; j<n; j++)
        {
            trDist=x[j]-x[i];
            trEnergy+=e[j];
            trGold+=g[j];

            //cout<<i<<" "<<j<<" "<<trDist<<" "<<trGold<<" "<<trEnergy<<endl;
            if (trEnergy>=trDist) ress=max(ress, trGold);
        }
    }*/
    cout<<ress;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -