Submission #155195

# Submission time Handle Problem Language Result Execution time Memory
155195 2019-09-27T04:32:21 Z kungfulon Art Exhibition (JOI18_art) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define repd(i,a,b) for(int i = (a);i >= (b);i--)
#define PB push_back
#define F first
#define S second
#define Task ""
using namespace std;
template <class T> T read(T &a){ifstream cin (Task".inp");a = 0;char c = cin.get();bool nega = 0;while(!isdigit(c) && c != '-')c = cin.get();if(c == '-')nega = 1,c = cin.get();a = c - 48;c = cin.get();while(isdigit(c))a = a * 10 + c - 48,c = cin.get();if(nega)a = -a;return a;}
template <class T> void writep(T a){ofstream cout (Task".out");if(a > 9)writep(a / 10);cout.put(a % 10 + 48);}
template <class T> void write(T a){ofstream cout (Task".out");if(a < 0)cout.put('-'),a = -a;writep(a);cout.put(' ');}
template <class T> void writeln(T a){ofstream cout (Task".out");write(a);cout.put('\n');}
const int N = 500012;
int n;
pair<long long,long long> a[N];
struct seg
{
    long long t[4*N];
    #define mid ((l + r)/2)
    long long build(int l,int r,int id)
    {
        if(l == r) return t[id] = a[l].S - a[l].F;
        return t[id] = max(build(l,mid,id*2),build(mid+1,r,id*2+1));
    }
    long long get(int l,int r,int id,int u,int v)
    {
        if(l > v || r < u) return -1;
        if(l >= u && r <= v) return t[id];
        return max(get(l,mid,id*2,u,v),get(mid+1,r,id*2+1,u,v));
    }


}IT;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    ifstream  cin (Task".inp");
//    ofstream cout (Task".out");
    cin >> n;
    rep(i,1,n)
        cin >> a[i].F >> a[i].S;
    sort(a+1,a+n+1);
    rep(i,1,n) a[i].S += a[i-1].S;
    long long ans = 0;
    IT.build(1,n,1);
    rep(i,1,n)
        ans = max(ans,IT.get(1,n,1,i,n) + a[i].F - a[i-1].S);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -