Submission #207736

# Submission time Handle Problem Language Result Execution time Memory
207736 2020-03-08T17:51:18 Z Lightning Art Exhibition (JOI18_art) C++14
100 / 100
300 ms 16760 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define int ll

const int szT = (1 << 19) - 1;
const int INF = 1e9 + 5;

int n, ans;
pll a[szT];
ll t[szT * 4];

void upd(int pos, ll x) {
	pos += szT;
	t[pos] = x;
	while((pos /= 2) >= 1) {
		t[pos] = min(t[pos * 2], t[pos * 2 + 1]);
	}
}

ll get(int l, int r) {
	ll res = INF;
	for(l += szT, r += szT; l <= r; l /= 2, r /= 2) {
		if(l % 2 == 1) res = min(res, t[l++]);
		if(r % 2 == 0) res = min(res, t[r--]);
		if(l > r) break;
	}
	return res;
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].F >> a[i].S;
	}
	sort(a + 1, a + n + 1);
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		sum += a[i].S;
      	ans = max(ans, a[i].S);
		if (1 < i) ans = max(ans, sum - a[i].F - get(1, i - 1));
		upd(i, (sum - a[i].S) - a[i].F);
	}
	cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/

Compilation message

art.cpp:78:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main () {
        ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 8 ms 632 KB Output is correct
28 Correct 7 ms 632 KB Output is correct
29 Correct 7 ms 632 KB Output is correct
30 Correct 7 ms 632 KB Output is correct
31 Correct 8 ms 760 KB Output is correct
32 Correct 7 ms 636 KB Output is correct
33 Correct 8 ms 764 KB Output is correct
34 Correct 7 ms 632 KB Output is correct
35 Correct 7 ms 632 KB Output is correct
36 Correct 7 ms 632 KB Output is correct
37 Correct 8 ms 632 KB Output is correct
38 Correct 7 ms 636 KB Output is correct
39 Correct 7 ms 632 KB Output is correct
40 Correct 7 ms 632 KB Output is correct
41 Correct 7 ms 632 KB Output is correct
42 Correct 8 ms 632 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 7 ms 760 KB Output is correct
45 Correct 7 ms 632 KB Output is correct
46 Correct 8 ms 632 KB Output is correct
47 Correct 7 ms 632 KB Output is correct
48 Correct 7 ms 632 KB Output is correct
49 Correct 7 ms 632 KB Output is correct
50 Correct 9 ms 760 KB Output is correct
51 Correct 7 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 8 ms 632 KB Output is correct
28 Correct 7 ms 632 KB Output is correct
29 Correct 7 ms 632 KB Output is correct
30 Correct 7 ms 632 KB Output is correct
31 Correct 8 ms 760 KB Output is correct
32 Correct 7 ms 636 KB Output is correct
33 Correct 8 ms 764 KB Output is correct
34 Correct 7 ms 632 KB Output is correct
35 Correct 7 ms 632 KB Output is correct
36 Correct 7 ms 632 KB Output is correct
37 Correct 8 ms 632 KB Output is correct
38 Correct 7 ms 636 KB Output is correct
39 Correct 7 ms 632 KB Output is correct
40 Correct 7 ms 632 KB Output is correct
41 Correct 7 ms 632 KB Output is correct
42 Correct 8 ms 632 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 7 ms 760 KB Output is correct
45 Correct 7 ms 632 KB Output is correct
46 Correct 8 ms 632 KB Output is correct
47 Correct 7 ms 632 KB Output is correct
48 Correct 7 ms 632 KB Output is correct
49 Correct 7 ms 632 KB Output is correct
50 Correct 9 ms 760 KB Output is correct
51 Correct 7 ms 632 KB Output is correct
52 Correct 284 ms 16760 KB Output is correct
53 Correct 297 ms 16428 KB Output is correct
54 Correct 280 ms 16376 KB Output is correct
55 Correct 300 ms 16408 KB Output is correct
56 Correct 282 ms 16504 KB Output is correct
57 Correct 287 ms 16376 KB Output is correct
58 Correct 291 ms 16452 KB Output is correct
59 Correct 291 ms 16376 KB Output is correct
60 Correct 285 ms 16512 KB Output is correct
61 Correct 287 ms 16376 KB Output is correct
62 Correct 279 ms 16376 KB Output is correct
63 Correct 283 ms 16380 KB Output is correct
64 Correct 280 ms 16376 KB Output is correct
65 Correct 298 ms 16376 KB Output is correct
66 Correct 282 ms 16376 KB Output is correct
67 Correct 285 ms 16480 KB Output is correct
68 Correct 282 ms 16468 KB Output is correct