Submission #981956

#TimeUsernameProblemLanguageResultExecution timeMemory
981956Amirreza_FakhriArt Exhibition (JOI18_art)C++17
100 / 100
138 ms21064 KiB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 5e5+5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
vector <pii> v;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        v.pb(mp(a, b));
    }
    sort(all(v));
    int ans = v[0].S, dp = v[0].S;
    for (int i = 1; i < n; i++) {
        // cout << ans << ' ' << i-1 << '\n';
        dp = max(v[i].S, dp+v[i].S-(v[i].F-v[i-1].F));
        smax(ans, dp);
    }
    cout << ans << '\n';
    return 0;
}





/*
srand(time(0));
cout << (rand()%1900) + 1 << ' ' << (rand()%2)+5 << '\n';
*/






















#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...