Submission #78534

# Submission time Handle Problem Language Result Execution time Memory
78534 2018-10-05T17:15:41 Z Origims Art Exhibition (JOI18_art) C++14
100 / 100
257 ms 222916 KB
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 5e5 + 20;
pii a[N];
ll n, ans;

void solve(int l, int r) {
	if (r - l < 2) {
		ans = max(ans, a[l].S);
		return ;
	}
	int mid = (l + r) / 2;
	solve(l, mid);
	solve(mid, r);
	ll sum = 0, res = 0;
	for (int i = mid - 1; i >= l; i--) {
		sum += a[i].S;
		res = max(res, sum - (a[mid].F - a[i].F));
	}
	sum = 0;
	for (int i = mid; i < r; i++) {
		sum += a[i].S;
		ans = max(ans, sum - (a[i].F - a[mid].F) + res);
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i].F >> a[i].S;
	sort(a, a + n);
	solve(0, n);
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 10 ms 688 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 10 ms 688 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 824 KB Output is correct
17 Correct 3 ms 824 KB Output is correct
18 Correct 2 ms 824 KB Output is correct
19 Correct 2 ms 824 KB Output is correct
20 Correct 2 ms 836 KB Output is correct
21 Correct 2 ms 840 KB Output is correct
22 Correct 3 ms 976 KB Output is correct
23 Correct 2 ms 976 KB Output is correct
24 Correct 2 ms 1052 KB Output is correct
25 Correct 2 ms 1052 KB Output is correct
26 Correct 2 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 10 ms 688 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 824 KB Output is correct
17 Correct 3 ms 824 KB Output is correct
18 Correct 2 ms 824 KB Output is correct
19 Correct 2 ms 824 KB Output is correct
20 Correct 2 ms 836 KB Output is correct
21 Correct 2 ms 840 KB Output is correct
22 Correct 3 ms 976 KB Output is correct
23 Correct 2 ms 976 KB Output is correct
24 Correct 2 ms 1052 KB Output is correct
25 Correct 2 ms 1052 KB Output is correct
26 Correct 2 ms 1052 KB Output is correct
27 Correct 4 ms 1092 KB Output is correct
28 Correct 4 ms 1220 KB Output is correct
29 Correct 4 ms 1348 KB Output is correct
30 Correct 4 ms 1480 KB Output is correct
31 Correct 4 ms 1604 KB Output is correct
32 Correct 4 ms 1732 KB Output is correct
33 Correct 4 ms 2020 KB Output is correct
34 Correct 4 ms 2244 KB Output is correct
35 Correct 4 ms 2276 KB Output is correct
36 Correct 4 ms 2276 KB Output is correct
37 Correct 4 ms 2396 KB Output is correct
38 Correct 4 ms 2504 KB Output is correct
39 Correct 4 ms 2632 KB Output is correct
40 Correct 4 ms 2760 KB Output is correct
41 Correct 4 ms 2888 KB Output is correct
42 Correct 4 ms 3016 KB Output is correct
43 Correct 4 ms 3160 KB Output is correct
44 Correct 4 ms 3268 KB Output is correct
45 Correct 4 ms 3396 KB Output is correct
46 Correct 4 ms 3652 KB Output is correct
47 Correct 4 ms 3652 KB Output is correct
48 Correct 4 ms 3780 KB Output is correct
49 Correct 4 ms 3908 KB Output is correct
50 Correct 4 ms 4036 KB Output is correct
51 Correct 4 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 10 ms 688 KB Output is correct
7 Correct 2 ms 688 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 824 KB Output is correct
17 Correct 3 ms 824 KB Output is correct
18 Correct 2 ms 824 KB Output is correct
19 Correct 2 ms 824 KB Output is correct
20 Correct 2 ms 836 KB Output is correct
21 Correct 2 ms 840 KB Output is correct
22 Correct 3 ms 976 KB Output is correct
23 Correct 2 ms 976 KB Output is correct
24 Correct 2 ms 1052 KB Output is correct
25 Correct 2 ms 1052 KB Output is correct
26 Correct 2 ms 1052 KB Output is correct
27 Correct 4 ms 1092 KB Output is correct
28 Correct 4 ms 1220 KB Output is correct
29 Correct 4 ms 1348 KB Output is correct
30 Correct 4 ms 1480 KB Output is correct
31 Correct 4 ms 1604 KB Output is correct
32 Correct 4 ms 1732 KB Output is correct
33 Correct 4 ms 2020 KB Output is correct
34 Correct 4 ms 2244 KB Output is correct
35 Correct 4 ms 2276 KB Output is correct
36 Correct 4 ms 2276 KB Output is correct
37 Correct 4 ms 2396 KB Output is correct
38 Correct 4 ms 2504 KB Output is correct
39 Correct 4 ms 2632 KB Output is correct
40 Correct 4 ms 2760 KB Output is correct
41 Correct 4 ms 2888 KB Output is correct
42 Correct 4 ms 3016 KB Output is correct
43 Correct 4 ms 3160 KB Output is correct
44 Correct 4 ms 3268 KB Output is correct
45 Correct 4 ms 3396 KB Output is correct
46 Correct 4 ms 3652 KB Output is correct
47 Correct 4 ms 3652 KB Output is correct
48 Correct 4 ms 3780 KB Output is correct
49 Correct 4 ms 3908 KB Output is correct
50 Correct 4 ms 4036 KB Output is correct
51 Correct 4 ms 4164 KB Output is correct
52 Correct 246 ms 24568 KB Output is correct
53 Correct 253 ms 37184 KB Output is correct
54 Correct 250 ms 49912 KB Output is correct
55 Correct 253 ms 62584 KB Output is correct
56 Correct 255 ms 75276 KB Output is correct
57 Correct 245 ms 87964 KB Output is correct
58 Correct 252 ms 100612 KB Output is correct
59 Correct 246 ms 113224 KB Output is correct
60 Correct 255 ms 125992 KB Output is correct
61 Correct 256 ms 138508 KB Output is correct
62 Correct 257 ms 151372 KB Output is correct
63 Correct 252 ms 163976 KB Output is correct
64 Correct 252 ms 175336 KB Output is correct
65 Correct 251 ms 187984 KB Output is correct
66 Correct 252 ms 199128 KB Output is correct
67 Correct 254 ms 211820 KB Output is correct
68 Correct 250 ms 222916 KB Output is correct