Submission #1108590

# Submission time Handle Problem Language Result Execution time Memory
1108590 2024-11-04T14:12:49 Z vjudge1 Art Exhibition (JOI18_art) C++
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;
long long ans,c,n;
pair<long long,long long>a[500005];
struct tutao{long long val,lazy;}st[200020];
void Down(ll id)
{
    long long t=st[id].lazy;
    st[id*2].val+=t;
    st[id*2].lazy+=t;

    st[id*2+1].val+=t;
    st[id*2+1].lazy+=t;
    st[id].lazy=0;
}
void Update(ll id,ll l,ll r,ll u,ll v,ll val)
{
    if(r<u||v<l)return;
    if(u<=l&&r<=v)
    {
        st[id].val+=val;
        st[id].lazy+=val;
        return;
    }
    Down(id);
    ll mid=(l+r)/2;
    Update(id*2,l,mid,u,v,val);
    Update(id*2+1,mid+1,r,u,v,val);
    st[id].val=max(st[id*2].val,st[id*2+1].val);
}
long long Get(ll id,ll l,ll r,ll u,ll v)
{
    if(r<u||v<l)return -1e18;
    if(u<=l&&r<=v)return st[id].val;
    Down(id);
    ll mid=(l+r)/2;
    return max(Get(id*2,l,mid,u,v),Get(id*2+1,mid+1,r,u,v));
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("code.inp","r",stdin);
    //freopen("code.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
    sort(a+1,a+n+1);
    ans=a[1].second;
    Update(1,1,n,1,1,a[1].first+a[1].second);
    for(int i=2;i<=n;i++)
    {
        c=Get(1,1,n,1,i-1);
        ans=max(ans,c+a[i].second-a[i].first);
        Update(1,1,n,i,i,a[i].first+a[i].second);
        Update(1,1,n,1,i-1,a[i].second);
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -