Submission #171710

# Submission time Handle Problem Language Result Execution time Memory
171710 2019-12-30T07:06:53 Z dennisstar Art Exhibition (JOI18_art) C++11
100 / 100
334 ms 36924 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

int N;
pll ar[500010];
ll B[500010], C[500010];
ll seg[(1<<20)];
ll x, y;

ll mx(int fr, int re) {
	fr+=(1<<19); re+=(1<<19);
	ll ret=seg[0];
	while (fr<=re) {
		if (fr%2) ret=max(ret, seg[fr++]);
		if (re%2==0) ret=max(ret, seg[re--]);
		fr/=2; re/=2;
	}
	return ret;
}

int main() {
	scanf("%d", &N);
	for (int i=0; i<N; i++) {
		scanf("%lld %lld", &x, &y);
		ar[i]={x, y};
	}
	sort(ar, ar+N);
	for (int i=0; i<N; i++) B[i]=ar[i].se, C[i]=ar[i].fi+ar[i].se-ar[i+1].fi;
	for (int i=N-1; i>=0; i--) seg[i+(1<<19)]=seg[i+1+(1<<19)]+C[i];
	for (int i=(1<<19)-1; i; i--) seg[i]=max(seg[i*2], seg[i*2+1]);
	ll ans=B[0], s=0;
	for (int i=N-1; i; i--) {
		s+=C[i];
		ans=max(ans, mx(0, i-1)-s+B[i]);
		ans=max(ans, B[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
art.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4476 KB Output is correct
2 Correct 7 ms 4472 KB Output is correct
3 Correct 7 ms 4472 KB Output is correct
4 Correct 7 ms 4460 KB Output is correct
5 Correct 7 ms 4448 KB Output is correct
6 Correct 7 ms 4472 KB Output is correct
7 Correct 7 ms 4472 KB Output is correct
8 Correct 7 ms 4472 KB Output is correct
9 Correct 7 ms 4472 KB Output is correct
10 Correct 7 ms 4472 KB Output is correct
11 Correct 7 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4476 KB Output is correct
2 Correct 7 ms 4472 KB Output is correct
3 Correct 7 ms 4472 KB Output is correct
4 Correct 7 ms 4460 KB Output is correct
5 Correct 7 ms 4448 KB Output is correct
6 Correct 7 ms 4472 KB Output is correct
7 Correct 7 ms 4472 KB Output is correct
8 Correct 7 ms 4472 KB Output is correct
9 Correct 7 ms 4472 KB Output is correct
10 Correct 7 ms 4472 KB Output is correct
11 Correct 7 ms 4472 KB Output is correct
12 Correct 7 ms 4472 KB Output is correct
13 Correct 7 ms 4472 KB Output is correct
14 Correct 8 ms 4600 KB Output is correct
15 Correct 7 ms 4472 KB Output is correct
16 Correct 7 ms 4472 KB Output is correct
17 Correct 7 ms 4472 KB Output is correct
18 Correct 7 ms 4472 KB Output is correct
19 Correct 7 ms 4444 KB Output is correct
20 Correct 7 ms 4472 KB Output is correct
21 Correct 7 ms 4472 KB Output is correct
22 Correct 7 ms 4472 KB Output is correct
23 Correct 7 ms 4472 KB Output is correct
24 Correct 7 ms 4444 KB Output is correct
25 Correct 7 ms 4472 KB Output is correct
26 Correct 7 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4476 KB Output is correct
2 Correct 7 ms 4472 KB Output is correct
3 Correct 7 ms 4472 KB Output is correct
4 Correct 7 ms 4460 KB Output is correct
5 Correct 7 ms 4448 KB Output is correct
6 Correct 7 ms 4472 KB Output is correct
7 Correct 7 ms 4472 KB Output is correct
8 Correct 7 ms 4472 KB Output is correct
9 Correct 7 ms 4472 KB Output is correct
10 Correct 7 ms 4472 KB Output is correct
11 Correct 7 ms 4472 KB Output is correct
12 Correct 7 ms 4472 KB Output is correct
13 Correct 7 ms 4472 KB Output is correct
14 Correct 8 ms 4600 KB Output is correct
15 Correct 7 ms 4472 KB Output is correct
16 Correct 7 ms 4472 KB Output is correct
17 Correct 7 ms 4472 KB Output is correct
18 Correct 7 ms 4472 KB Output is correct
19 Correct 7 ms 4444 KB Output is correct
20 Correct 7 ms 4472 KB Output is correct
21 Correct 7 ms 4472 KB Output is correct
22 Correct 7 ms 4472 KB Output is correct
23 Correct 7 ms 4472 KB Output is correct
24 Correct 7 ms 4444 KB Output is correct
25 Correct 7 ms 4472 KB Output is correct
26 Correct 7 ms 4472 KB Output is correct
27 Correct 10 ms 4732 KB Output is correct
28 Correct 10 ms 4728 KB Output is correct
29 Correct 10 ms 4728 KB Output is correct
30 Correct 10 ms 4728 KB Output is correct
31 Correct 10 ms 4728 KB Output is correct
32 Correct 10 ms 4728 KB Output is correct
33 Correct 10 ms 4728 KB Output is correct
34 Correct 10 ms 4716 KB Output is correct
35 Correct 10 ms 4788 KB Output is correct
36 Correct 10 ms 4856 KB Output is correct
37 Correct 10 ms 4856 KB Output is correct
38 Correct 10 ms 4856 KB Output is correct
39 Correct 10 ms 4856 KB Output is correct
40 Correct 10 ms 4728 KB Output is correct
41 Correct 10 ms 4728 KB Output is correct
42 Correct 10 ms 4728 KB Output is correct
43 Correct 11 ms 4856 KB Output is correct
44 Correct 10 ms 4856 KB Output is correct
45 Correct 10 ms 4728 KB Output is correct
46 Correct 10 ms 4728 KB Output is correct
47 Correct 11 ms 4732 KB Output is correct
48 Correct 33 ms 4828 KB Output is correct
49 Correct 10 ms 4728 KB Output is correct
50 Correct 11 ms 4700 KB Output is correct
51 Correct 11 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4476 KB Output is correct
2 Correct 7 ms 4472 KB Output is correct
3 Correct 7 ms 4472 KB Output is correct
4 Correct 7 ms 4460 KB Output is correct
5 Correct 7 ms 4448 KB Output is correct
6 Correct 7 ms 4472 KB Output is correct
7 Correct 7 ms 4472 KB Output is correct
8 Correct 7 ms 4472 KB Output is correct
9 Correct 7 ms 4472 KB Output is correct
10 Correct 7 ms 4472 KB Output is correct
11 Correct 7 ms 4472 KB Output is correct
12 Correct 7 ms 4472 KB Output is correct
13 Correct 7 ms 4472 KB Output is correct
14 Correct 8 ms 4600 KB Output is correct
15 Correct 7 ms 4472 KB Output is correct
16 Correct 7 ms 4472 KB Output is correct
17 Correct 7 ms 4472 KB Output is correct
18 Correct 7 ms 4472 KB Output is correct
19 Correct 7 ms 4444 KB Output is correct
20 Correct 7 ms 4472 KB Output is correct
21 Correct 7 ms 4472 KB Output is correct
22 Correct 7 ms 4472 KB Output is correct
23 Correct 7 ms 4472 KB Output is correct
24 Correct 7 ms 4444 KB Output is correct
25 Correct 7 ms 4472 KB Output is correct
26 Correct 7 ms 4472 KB Output is correct
27 Correct 10 ms 4732 KB Output is correct
28 Correct 10 ms 4728 KB Output is correct
29 Correct 10 ms 4728 KB Output is correct
30 Correct 10 ms 4728 KB Output is correct
31 Correct 10 ms 4728 KB Output is correct
32 Correct 10 ms 4728 KB Output is correct
33 Correct 10 ms 4728 KB Output is correct
34 Correct 10 ms 4716 KB Output is correct
35 Correct 10 ms 4788 KB Output is correct
36 Correct 10 ms 4856 KB Output is correct
37 Correct 10 ms 4856 KB Output is correct
38 Correct 10 ms 4856 KB Output is correct
39 Correct 10 ms 4856 KB Output is correct
40 Correct 10 ms 4728 KB Output is correct
41 Correct 10 ms 4728 KB Output is correct
42 Correct 10 ms 4728 KB Output is correct
43 Correct 11 ms 4856 KB Output is correct
44 Correct 10 ms 4856 KB Output is correct
45 Correct 10 ms 4728 KB Output is correct
46 Correct 10 ms 4728 KB Output is correct
47 Correct 11 ms 4732 KB Output is correct
48 Correct 33 ms 4828 KB Output is correct
49 Correct 10 ms 4728 KB Output is correct
50 Correct 11 ms 4700 KB Output is correct
51 Correct 11 ms 4856 KB Output is correct
52 Correct 334 ms 36680 KB Output is correct
53 Correct 326 ms 36864 KB Output is correct
54 Correct 325 ms 36732 KB Output is correct
55 Correct 334 ms 36860 KB Output is correct
56 Correct 325 ms 36740 KB Output is correct
57 Correct 333 ms 36712 KB Output is correct
58 Correct 331 ms 36764 KB Output is correct
59 Correct 329 ms 36728 KB Output is correct
60 Correct 324 ms 36728 KB Output is correct
61 Correct 327 ms 36600 KB Output is correct
62 Correct 327 ms 36924 KB Output is correct
63 Correct 329 ms 36796 KB Output is correct
64 Correct 327 ms 36804 KB Output is correct
65 Correct 325 ms 36708 KB Output is correct
66 Correct 326 ms 36728 KB Output is correct
67 Correct 324 ms 36728 KB Output is correct
68 Correct 321 ms 36724 KB Output is correct