Submission #791152

#TimeUsernameProblemLanguageResultExecution timeMemory
791152n3rm1nArt Exhibition (JOI18_art)C++17
100 / 100
167 ms40708 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN = 5e5 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n; vector < pair < long long , long long > > g; long long a[MAXN], b[MAXN]; long long p[MAXN]; void read() { cin >> n; g.push_back(make_pair(-1, -1)); for (long long i = 1; i <= n; ++ i) cin >> a[i] >> b[i]; for (long long i = 1; i <= n; ++ i) { g.push_back(make_pair(a[i], b[i])); } sort(g.begin(), g.end()); for (long long i = 1; i <= n; ++ i) { p[i] = p[i-1] + g[i].second; } } void solve() { priority_queue < long long > q; long long ans = 0, cost = 0; for (int i = 1; i <= n; ++ i) { q.push(g[i].first - p[i-1]); cost = q.top() + p[i] - g[i].first; ans = max(cost, ans); } cout << ans << endl; } int main() { speed(); read(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...