제출 #1159682

#제출 시각아이디문제언어결과실행 시간메모리
1159682eldorbek_008Art Exhibition (JOI18_art)C++17
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t

int32_t main() {
	ios :: sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;
	vector<array<int, 2>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1];
	}
	sort(a.begin(), a.end());
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		p[i] = (i == 0 ? 0 : p[i - 1]) + a[i][1];
	}
	int j = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		int d = a[i][0] - a[j][0];
		int s = p[i] - (j == 0 ? 0 : p[j - 1]);
		if (s <= d) {
			j = i;
		}
		d = a[i][0] - a[j][0];
		s = p[i] - (j == 0 ? 0 : p[j - 1]);
		ans = max(ans, s - d);
	}
	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...