Submission #1088543

#TimeUsernameProblemLanguageResultExecution timeMemory
1088543StaheosArt Exhibition (JOI18_art)C++14
0 / 100
1 ms344 KiB
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	long long n;
	cin >> n;
	auto ab = new pair<long long, long long>[n];

	for (long long i = 0; i < n; i++)
	{
		cin >> ab[i].first >> ab[i].second;
	}
	std::sort(ab, ab + n);

	long long amin = 0;
	long long s = 0;
	long long m = 0;
	for (long long i = 0; i < n; i++)
	{
		s += ab[i].second;
		while (amin + 1 < n && (s - (ab[i].first - ab[amin].first) < s - ab[amin].second - (ab[i].first - ab[amin + 1].first)))
		{
			s -= ab[amin].second;
			amin++;
		}
		if (s - (ab[i].first - ab[amin].first) > m)
		{
			m = s - (ab[i].first - ab[amin].first);
		}
	}

	cout << m << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...