Submission #787597

#TimeUsernameProblemLanguageResultExecution timeMemory
787597mannshah1211Art Exhibition (JOI18_art)C++17
100 / 100
426 ms21384 KiB
// I'm back in action #include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define f first #define s second #define pb push_back #define forn(i, n) for (int i = 0; i < n; i++) int32_t main() { int n; cin >> n; vector<pair<int, int>> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i].f >> a[i].s; } sort(a.begin() + 1, a.end()); vector<int> pref(n + 1); for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + a[i].s; } int ans = -1e18; int mx = -1e18; for (int r = 1; r <= n; r++) { mx = max(mx, a[r].f - pref[r - 1]); ans = max(ans, pref[r] - a[r].f + mx); } cout << ans << '\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...