# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
913855 | cot | Art Exhibition (JOI18_art) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define pii pair <int,int>
#define r0 return 0
using namespace std;
const int N = 5 * 1e5 + 5;
int x,m,k,n,l,r,ans,cheese;
int pref[N],p[N],mn;
pii a[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].ff >> a[i].ss;
}
sort(a + 1,a + 1 + n);
p[0] = -a[1].ff;
pref[0] = 0;
for (int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + a[i].ss;
p[i] = min(p[i - 1],pref[i] - a[i].ff);
}
k = -LLONG_MAX;
for (int i = 1; i <= n; i++) {
k = max(k,pref[i] - a[i].ff - p[i - 1]);
}
cout << k << endl;
r0;
}