Submission #72979

# Submission time Handle Problem Language Result Execution time Memory
72979 2018-08-27T11:54:15 Z Diuven Art Exhibition (JOI18_art) C++14
100 / 100
381 ms 235060 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
const int MX=500010;

int n;
pli P[MX];
ll S[MX], A[MX], ans;

inline ll get(int x){ return S[x]-A[x]; }

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for(int i=1; i<=n; i++) cin>>P[i].first>>P[i].second;

	sort(P+1, P+n+1);
	for(int i=1; i<=n; i++) A[i]=P[i].first;
	for(int i=1; i<=n; i++) S[i]=S[i-1]+P[i].second;

	vector<int> V;
	for(int i=n; i>=1; i--)
		if(V.empty() || get(V.back())<get(i)) V.push_back(i);
	reverse(V.begin(), V.end());

	for(int i=1, p=0; i<=n; i++){
		while(p+1<(int)V.size() && V[p]<i) p++;
		ans=max(ans, get(V[p])-S[i-1]+A[i]);
	}

	cout<<ans<<'\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 4 ms 664 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 3 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 4 ms 664 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 3 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 712 KB Output is correct
14 Correct 3 ms 736 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
16 Correct 4 ms 784 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 932 KB Output is correct
19 Correct 3 ms 932 KB Output is correct
20 Correct 3 ms 932 KB Output is correct
21 Correct 2 ms 932 KB Output is correct
22 Correct 2 ms 1064 KB Output is correct
23 Correct 3 ms 1064 KB Output is correct
24 Correct 3 ms 1064 KB Output is correct
25 Correct 3 ms 1064 KB Output is correct
26 Correct 2 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 4 ms 664 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 3 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 712 KB Output is correct
14 Correct 3 ms 736 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
16 Correct 4 ms 784 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 932 KB Output is correct
19 Correct 3 ms 932 KB Output is correct
20 Correct 3 ms 932 KB Output is correct
21 Correct 2 ms 932 KB Output is correct
22 Correct 2 ms 1064 KB Output is correct
23 Correct 3 ms 1064 KB Output is correct
24 Correct 3 ms 1064 KB Output is correct
25 Correct 3 ms 1064 KB Output is correct
26 Correct 2 ms 1064 KB Output is correct
27 Correct 6 ms 1220 KB Output is correct
28 Correct 9 ms 1348 KB Output is correct
29 Correct 6 ms 1516 KB Output is correct
30 Correct 7 ms 1680 KB Output is correct
31 Correct 6 ms 1844 KB Output is correct
32 Correct 6 ms 1860 KB Output is correct
33 Correct 6 ms 1988 KB Output is correct
34 Correct 7 ms 2116 KB Output is correct
35 Correct 6 ms 2244 KB Output is correct
36 Correct 7 ms 2372 KB Output is correct
37 Correct 6 ms 2500 KB Output is correct
38 Correct 7 ms 2632 KB Output is correct
39 Correct 7 ms 2760 KB Output is correct
40 Correct 7 ms 2952 KB Output is correct
41 Correct 7 ms 2952 KB Output is correct
42 Correct 6 ms 3144 KB Output is correct
43 Correct 7 ms 3264 KB Output is correct
44 Correct 7 ms 3392 KB Output is correct
45 Correct 6 ms 3520 KB Output is correct
46 Correct 6 ms 3664 KB Output is correct
47 Correct 6 ms 3776 KB Output is correct
48 Correct 7 ms 3928 KB Output is correct
49 Correct 6 ms 4036 KB Output is correct
50 Correct 5 ms 4160 KB Output is correct
51 Correct 7 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 4 ms 664 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 3 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 712 KB Output is correct
14 Correct 3 ms 736 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
16 Correct 4 ms 784 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 932 KB Output is correct
19 Correct 3 ms 932 KB Output is correct
20 Correct 3 ms 932 KB Output is correct
21 Correct 2 ms 932 KB Output is correct
22 Correct 2 ms 1064 KB Output is correct
23 Correct 3 ms 1064 KB Output is correct
24 Correct 3 ms 1064 KB Output is correct
25 Correct 3 ms 1064 KB Output is correct
26 Correct 2 ms 1064 KB Output is correct
27 Correct 6 ms 1220 KB Output is correct
28 Correct 9 ms 1348 KB Output is correct
29 Correct 6 ms 1516 KB Output is correct
30 Correct 7 ms 1680 KB Output is correct
31 Correct 6 ms 1844 KB Output is correct
32 Correct 6 ms 1860 KB Output is correct
33 Correct 6 ms 1988 KB Output is correct
34 Correct 7 ms 2116 KB Output is correct
35 Correct 6 ms 2244 KB Output is correct
36 Correct 7 ms 2372 KB Output is correct
37 Correct 6 ms 2500 KB Output is correct
38 Correct 7 ms 2632 KB Output is correct
39 Correct 7 ms 2760 KB Output is correct
40 Correct 7 ms 2952 KB Output is correct
41 Correct 7 ms 2952 KB Output is correct
42 Correct 6 ms 3144 KB Output is correct
43 Correct 7 ms 3264 KB Output is correct
44 Correct 7 ms 3392 KB Output is correct
45 Correct 6 ms 3520 KB Output is correct
46 Correct 6 ms 3664 KB Output is correct
47 Correct 6 ms 3776 KB Output is correct
48 Correct 7 ms 3928 KB Output is correct
49 Correct 6 ms 4036 KB Output is correct
50 Correct 5 ms 4160 KB Output is correct
51 Correct 7 ms 4292 KB Output is correct
52 Correct 381 ms 34700 KB Output is correct
53 Correct 255 ms 46356 KB Output is correct
54 Correct 264 ms 58284 KB Output is correct
55 Correct 273 ms 70448 KB Output is correct
56 Correct 288 ms 83088 KB Output is correct
57 Correct 300 ms 95716 KB Output is correct
58 Correct 275 ms 108452 KB Output is correct
59 Correct 248 ms 121092 KB Output is correct
60 Correct 244 ms 133824 KB Output is correct
61 Correct 257 ms 146296 KB Output is correct
62 Correct 282 ms 158868 KB Output is correct
63 Correct 271 ms 171708 KB Output is correct
64 Correct 284 ms 184396 KB Output is correct
65 Correct 274 ms 197100 KB Output is correct
66 Correct 336 ms 209648 KB Output is correct
67 Correct 307 ms 222324 KB Output is correct
68 Correct 292 ms 235060 KB Output is correct