제출 #355019

#제출 시각아이디문제언어결과실행 시간메모리
355019SeDunionArt Exhibition (JOI18_art)C++17
100 / 100
235 ms14316 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

// a[i]<a[i+1]
// max(p[i] - p[j - 1] - (a[i] - a[j]))
// max(p[i] - p[j - 1] - a[i] + a[j])
// max(-a[i] + p[i] + a[j] - p[j - 1])

using pll = pair<ll,ll>;
pll a[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a + 1, a + 1 + n);
	ll pref = 0;
	ll mx = -(ll(1e18));
	ll Ans = -(ll(1e18));
	for (int i = 1 ; i <= n ; ++ i) {
		mx = max(mx, a[i].first - pref);
		pref += a[i].second;
		Ans = max(Ans, -a[i].first + pref + mx);
	}
	cout << Ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...