제출 #126161

#제출 시각아이디문제언어결과실행 시간메모리
126161AlexLuchianovArt Exhibition (JOI18_art)C++14
100 / 100
255 ms12196 KiB
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 500000;
ll const inf = 10000000000000000;

struct number{
  ll cost;
  ll sz;
  bool operator < (number const &a) const{
    return sz < a.sz;
  }
};
number v[1 + nmax];
ll sum[1 + nmax];

int main()
{
  ios::sync_with_stdio(0);
  cin.tie();

  int n;
  cin >> n;
  for(int i = 1;i <= n; i++){
    cin >> v[i].sz >> v[i].cost;
  }
  sort(v + 1, v + n + 1);
  for(int i = 1;i <= n ; i++)
    sum[i] = sum[i - 1] + v[i].cost;

  ll smax = 0;
  ll smin = inf;
  for(int i = 1;i <= n; i++){
    smin = MIN(smin, sum[i - 1] - v[i].sz);
    smax = MAX(smax, sum[i] - v[i].sz - smin);
  }

  cout << smax;

  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...