Submission #1285731

#TimeUsernameProblemLanguageResultExecution timeMemory
1285731nemkhoArt Exhibition (JOI18_art)C++17
100 / 100
167 ms12204 KiB
#include <bits/stdc++.h> #define ll long long #define pr pair <ll, ll> #define fi first #define se second using namespace std; const int N = 5e5 + 5; ll pre[N], n, res = -1e18; pr a[N]; void inp() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se; sort(a + 1, a + n + 1); } void solve() { for (int i = 1; i <= n; i++) { res = max(res, a[i].se); pre[i] = pre[i-1] + a[i].se; } ll _max = a[1].fi; for (int i = 1; i <= n; i++) { res = max(res, pre[i] - a[i].fi + _max); _max = max(_max, a[i].fi - pre[i-1]); } cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); inp(); 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...