제출 #369108

#제출 시각아이디문제언어결과실행 시간메모리
369108Lam_lai_cuoc_doiArt Exhibition (JOI18_art)C++17
100 / 100
616 ms21100 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

const bool typetest = 0;
const int N = 5e5 + 5;
const ll Inf = 1e17;
int n;
struct OK
{
    ll x, y;
    bool operator<(const OK &a) const
    {
        return x < a.x;
    }
} a[N];

void Read()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i].x >> a[i].y;
    sort(a + 1, a + n + 1);
}

void Solve()
{
    a[0].y = 0;
    ll maxn(-Inf);
    ll ans(-Inf);
    for (int i = 1; i <= n; ++i)
    {
        a[i].y += a[i - 1].y;
        maxn = max(maxn, a[i].x - a[i - 1].y);
        ans = max(ans, maxn + a[i].y - a[i].x);
    }
    cout << ans;
}

int32_t main()
{
    //ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        Read();
        Solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...