Submission #42271

# Submission time Handle Problem Language Result Execution time Memory
42271 2018-02-24T19:03:57 Z RezwanArefin01 Art Exhibition (JOI18_art) C++14
0 / 100
1 ms 248 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii; 

const int maxn = 5e5 + 10;
struct lol {ll a, b;} art[maxn];

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	int n; cin >> n;
	for(int i = 1; i <= n; i++) 
		cin >> art[i].a >> art[i].b; 
	art[0].a = art[0].b = 0;
	sort(art, art + n + 1, [](lol &a, lol &b) { return a.a < b.a; });

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

	ll Max = art[1].b, add = art[1].a;
	for(int i = 2; i <= n; i++) {
/*		b[i] - b[j - 1] - a[i] + a[j]; 
		=> a[j] - b[j - 1] + b[i] - a[i];*/

		Max = max(Max, art[i].b - art[i].a + add);
		add = max(add, art[i].a - art[i - 1].b);
	}
	cout << Max << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -