Submission #162589

#TimeUsernameProblemLanguageResultExecution timeMemory
162589fenech20Art Exhibition (JOI18_art)C++14
100 / 100
341 ms20920 KiB
/**
 * Martin Leshko (leshko.martin@gmail.com)
 */

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define sz(a) (int)a.size()

const int N = 300001;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector< pair<long long, long long> > a(n);
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    a[i] = {x, y};
  }
  sort(a.begin(), a.end());
  long long prefix = 0, mn = 0x3f3f3f3f3f3f3f3f, ans = -0x3f3f3f3f3f3f3f3f;
  for (int i = 0; i < n; i++) {
    prefix += a[i].second;
    mn = min(mn, prefix - a[i].second - a[i].first);
    ans = max(ans, prefix - a[i].first - mn);
  }
  cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...