제출 #341577

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);
int const MAX = 5e5 + 7;

pl art[MAX];
ll pfx[MAX];

int main()
{
	fastio;

	int n;
	cin >> n;

	for (int i = 1; i <= n; ++i)
		cin >> art[i].f1 >> art[i].s2;
	sort(art+1, art+1+n);

	for (int i = 1; i <= n; ++i)
		pfx[i] = pfx[i-1] + art[i].s2;

	ll res = 0;
	for (int i = 1, j = 1; j < n; ++j)
	{	
		// using art [i, j]
		if (pfx[j-1] - pfx[i-1] < art[j].f1 - art[i].f1)
			i = j;
		res = max(res, pfx[j] - pfx[i-1] - (art[j].f1 - art[i].f1));
	}
	cout << res << '\n';

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