제출 #162588

#제출 시각아이디문제언어결과실행 시간메모리
162588fenech20Art Exhibition (JOI18_art)C++14
50 / 100
1022 ms20984 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() {
  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...