Submission #384337

# Submission time Handle Problem Language Result Execution time Memory
384337 2021-04-01T12:16:46 Z patrikpavic2 Bigger segments (IZhO19_segments) C++17
100 / 100
159 ms 21972 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;

const int N = 5e5 + 500;

int A[N], n, dp[N];
ll P[N];
priority_queue < pair < pair < ll, ll > , int > > pri;

int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", A + i);
		P[i] = A[i] + (i ? P[i - 1] : 0LL);
	}
	int ndp = 0; ll npr = 0;
	for(int i = 0;i < n;i++){
		while(!pri.empty() && -pri.top().X.X <= P[i]){
			if(pri.top().X.Y > npr){
				npr = pri.top().X.Y;
				ndp = pri.top().Y;
			}
			pri.pop();
		}	
		dp[i] = ndp + 1;
		pri.push({{-(2LL * P[i] - npr), P[i]}, dp[i]});
	}
	printf("%d\n", dp[n - 1]);
	return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
segments.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 2 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 1 ms 512 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 2 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 1 ms 512 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 17 ms 4960 KB Output is correct
47 Correct 27 ms 2860 KB Output is correct
48 Correct 24 ms 2796 KB Output is correct
49 Correct 22 ms 3372 KB Output is correct
50 Correct 19 ms 2924 KB Output is correct
51 Correct 28 ms 2924 KB Output is correct
52 Correct 15 ms 1644 KB Output is correct
53 Correct 9 ms 1132 KB Output is correct
54 Correct 23 ms 2156 KB Output is correct
55 Correct 27 ms 2924 KB Output is correct
56 Correct 16 ms 2412 KB Output is correct
57 Correct 21 ms 3940 KB Output is correct
58 Correct 20 ms 3048 KB Output is correct
59 Correct 16 ms 2412 KB Output is correct
60 Correct 20 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 2 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 1 ms 512 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 17 ms 4960 KB Output is correct
47 Correct 27 ms 2860 KB Output is correct
48 Correct 24 ms 2796 KB Output is correct
49 Correct 22 ms 3372 KB Output is correct
50 Correct 19 ms 2924 KB Output is correct
51 Correct 28 ms 2924 KB Output is correct
52 Correct 15 ms 1644 KB Output is correct
53 Correct 9 ms 1132 KB Output is correct
54 Correct 23 ms 2156 KB Output is correct
55 Correct 27 ms 2924 KB Output is correct
56 Correct 16 ms 2412 KB Output is correct
57 Correct 21 ms 3940 KB Output is correct
58 Correct 20 ms 3048 KB Output is correct
59 Correct 16 ms 2412 KB Output is correct
60 Correct 20 ms 2540 KB Output is correct
61 Correct 84 ms 21972 KB Output is correct
62 Correct 106 ms 16080 KB Output is correct
63 Correct 159 ms 13008 KB Output is correct
64 Correct 113 ms 12780 KB Output is correct
65 Correct 97 ms 13036 KB Output is correct
66 Correct 136 ms 13120 KB Output is correct
67 Correct 110 ms 10532 KB Output is correct
68 Correct 55 ms 5356 KB Output is correct
69 Correct 114 ms 9196 KB Output is correct
70 Correct 132 ms 13036 KB Output is correct
71 Correct 76 ms 10092 KB Output is correct
72 Correct 103 ms 16092 KB Output is correct
73 Correct 91 ms 13664 KB Output is correct
74 Correct 80 ms 11400 KB Output is correct
75 Correct 90 ms 11444 KB Output is correct