Submission #229507

#TimeUsernameProblemLanguageResultExecution timeMemory
229507hanagasumiArt Exhibition (JOI18_art)C++17
100 / 100
705 ms52964 KiB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>

#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll

using namespace std;
typedef long long ll;



signed main() {
	#ifdef PC
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);


	int n;
	cin >> n;
	int ans = 0, bal = 0, minn = 0;
	map<int, int> zer;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		zer[a] += b;
	}
	vector<pair<int, int>> have;
	for (auto x : zer) {
		have.pb(x);
		ans = max(ans, x.sc);
	}
	n = len(have);
	have.pb({100, 100});
	for (int i = 0; i < n; i++) {
		ans = max(ans, bal + have[i].sc - minn);
		bal += (have[i].sc - (have[i + 1].ft - have[i].ft));
		minn = min(minn, bal);
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...