답안 #289956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289956 2020-09-03T09:14:27 Z MasterTaster 금 캐기 (IZhO14_divide) C++14
100 / 100
65 ms 11760 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], seg[400010], poz[400010];
vector< pair<ll ,int> > prefiksi;

void build(int node, int l, int r)
{
    if (l==r)
    {
        seg[node]=prefiksi[l].yy;
        return;
    }
    int mid=l+(r-l)/2;
    build(2*node, l, mid);
    build(2*node+1, mid+1, r);
    seg[node]=min(seg[2*node], seg[2*node+1]);
}
int query(int node, int l, int r, int levo, int desno) ///[l, r]-gde sam u segmentnom; [levo, desno]-query
{
    if (levo>r || desno<l) return n+1;
    if (levo<=l && desno>=r) return seg[node];

    int mid=l+(r-l)/2;
    return min(query(2*node, l, mid, levo, desno),
               query(2*node+1, mid+1, r, levo, desno));
}

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;
    prefiksi.pb({0-x[0], 0});
    for (int i=1; i<n; i++)
    {
        energy+=e[i-1];
        dist=x[i];
        prefiksi.pb({energy-dist, i});
    }

    sort(prefiksi.begin(), prefiksi.end());

    build(1, 0, n-1);

    vector<int> prviClan;
    for (int i=0; i<n; i++) prviClan.pb(prefiksi[i].xx);

    energy=0, dist=0;
    for (int i=0; i<n; i++)
    {
        dist=x[i];
        energy+=e[i];
        ll razl=energy-dist;
        auto it=upper_bound(prviClan.begin(), prviClan.end(), razl);
        if (it==prviClan.end()) { poz[i]=prefiksi.size()-1; }
        else
        {
            if (distance(prviClan.begin(), it)==0) { poz[i]=-1; continue; }
            poz[i]=distance(prviClan.begin(), it)-1;
        }
    }

    for (int i=0; i<n; i++)
    {
        if (poz[i]==-1) continue;
        int j=query(1, 0, n-1, 0, poz[i]);
        if (j>i) continue;
        else
        {
            ll koliko=prefG[i];
            if (j>0) koliko-=prefG[j-1];
            ress=max(ress, koliko);
        }
    }

    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;
}
/*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});*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 4 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 4 ms 1024 KB Output is correct
25 Correct 3 ms 1024 KB Output is correct
26 Correct 6 ms 1408 KB Output is correct
27 Correct 6 ms 1536 KB Output is correct
28 Correct 24 ms 5616 KB Output is correct
29 Correct 24 ms 5872 KB Output is correct
30 Correct 46 ms 11760 KB Output is correct
31 Correct 42 ms 10568 KB Output is correct
32 Correct 41 ms 10604 KB Output is correct
33 Correct 63 ms 10388 KB Output is correct
34 Correct 61 ms 10476 KB Output is correct
35 Correct 65 ms 10988 KB Output is correct
36 Correct 64 ms 11116 KB Output is correct