답안 #476261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476261 2021-09-25T17:50:50 Z ogibogi2004 금 캐기 (IZhO14_divide) C++14
100 / 100
138 ms 8688 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e5+6;
const ll INF=2e17;
int n;
ll x[MAXN],g[MAXN],d[MAXN],pref[MAXN];
ll fen[MAXN];
vector<ll>v;
void update(int idx,ll val)
{
    idx++;
    for(;idx<MAXN;idx+=idx&(-idx))
    {
        fen[idx]=max(fen[idx],val);
    }
}
ll query(int idx)
{
    idx++;
    ll ret=-INF;
    for(;idx>0;idx-=idx&(-idx))
    {
        ret=max(ret,fen[idx]);
    }
    return ret;
}
ll pref1[MAXN],output=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i]>>g[i]>>d[i];
    }
    for(int i=1;i<MAXN;i++)
    {
        fen[i]=-INF;
    }
    v.push_back(0);
    for(int i=1;i<=n;i++)
    {
        pref[i]=pref[i-1]+d[i];
        pref1[i]=pref1[i-1]+g[i];
        v.push_back(pref[i]-x[i]);
        //cout<<i<<" "<<pref[i]-x[i]<<endl;
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<":\n";
        ll t=pref[i-1]-x[i];
        int l=0,r=v.size()-1,ans=-1,mid;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(t<=v[mid])
            {
                r=mid-1;
            }
            else
            {
                ans=mid;
                l=mid+1;
            }
        }
        ans++;
        //cout<<ans<<endl;
        update(ans+1,-pref1[i-1]);
        l=0,r=v.size()-1,ans=-1;
        t=pref[i]-x[i];
        while(l<=r)
        {
            mid=(l+r)/2;
            if(t<=v[mid])
            {
                r=mid-1;
            }
            else
            {
                ans=mid;
                l=mid+1;
            }
        }
        ans++;
        //cout<<ans<<endl;
        output=max(output,pref1[i]+query(ans+1));
    }
    cout<<output<<endl;
return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 2 ms 1100 KB Output is correct
18 Correct 4 ms 1172 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
22 Correct 3 ms 1148 KB Output is correct
23 Correct 7 ms 1564 KB Output is correct
24 Correct 7 ms 1468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 2 ms 1100 KB Output is correct
18 Correct 4 ms 1172 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
22 Correct 3 ms 1148 KB Output is correct
23 Correct 7 ms 1564 KB Output is correct
24 Correct 7 ms 1468 KB Output is correct
25 Correct 5 ms 1356 KB Output is correct
26 Correct 10 ms 1820 KB Output is correct
27 Correct 12 ms 1828 KB Output is correct
28 Correct 58 ms 4484 KB Output is correct
29 Correct 72 ms 4852 KB Output is correct
30 Correct 138 ms 8688 KB Output is correct
31 Correct 106 ms 7648 KB Output is correct
32 Correct 115 ms 7604 KB Output is correct
33 Correct 101 ms 7480 KB Output is correct
34 Correct 100 ms 7404 KB Output is correct
35 Correct 114 ms 8012 KB Output is correct
36 Correct 123 ms 8156 KB Output is correct