Submission #141537

#TimeUsernameProblemLanguageResultExecution timeMemory
141537DrumpfTheGodEmperorArt Exhibition (JOI18_art)C++14
100 / 100
250 ms13644 KiB
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 5e5 + 5;
struct Painting {
	int size, val;
	bool operator<(const Painting &rhs) {
		return size < rhs.size;
	}
} p[N];
int n;
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) cin >> p[i].size >> p[i].val;
	sort(p, p + n);
	fw (i, 1, n) p[i].val += p[i - 1].val;
	int ans = -infll, curMx = -infll;
	fw (i, 0, n) {
		curMx = max(curMx, p[i].size - (i ? p[i - 1].val : 0));
		ans = max(ans, p[i].val - p[i].size + curMx);
	}
	cout << ans;
	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...