#include <bits/stdc++.h>
#define gsn "Bigger segments"
#define ll long long
#define pii pair<int, ll>
#define gb(i, j) ((i >> j) & 1)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r) (rng);
}
const int maxn = 500005;
int n;
ll a[maxn], s[maxn];
pii dp[maxn];
void solve()
{
cin >> n;
fi(i, 1, n) cin >> a[i], s[i] = s[i - 1] + a[i];
multiset<pair<ll, pii>> se;
pii ma = {1, s[0]};
fi(i, 1, n)
{
dp[i] = {ma.first, s[i] - ma.second};
se.insert({ dp[i].second + s[i], make_pair(dp[i].first + 1, s[i]) });
while(se.size())
{
auto it = se.begin();
if(it->first <= s[i + 1])
{
se.erase(it);
ma = max(ma, it->second);
}
else break;
}
}
cout << dp[n].first;
}
int main()
{
if(fopen(gsn".inp", "r"))
{
freopen(gsn".inp", "r", stdin);
freopen(gsn".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int nTest = 1;
// cin >> nTest;
while(nTest --)
{
solve();
}
/// ------------------check time!-----------------///
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen(gsn".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(gsn".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2404 KB |
Output is correct |
31 |
Correct |
2 ms |
2660 KB |
Output is correct |
32 |
Correct |
1 ms |
2404 KB |
Output is correct |
33 |
Correct |
1 ms |
2404 KB |
Output is correct |
34 |
Correct |
1 ms |
2660 KB |
Output is correct |
35 |
Correct |
1 ms |
2400 KB |
Output is correct |
36 |
Correct |
1 ms |
2404 KB |
Output is correct |
37 |
Correct |
1 ms |
2400 KB |
Output is correct |
38 |
Correct |
1 ms |
2408 KB |
Output is correct |
39 |
Correct |
1 ms |
2408 KB |
Output is correct |
40 |
Correct |
1 ms |
2408 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2404 KB |
Output is correct |
31 |
Correct |
2 ms |
2660 KB |
Output is correct |
32 |
Correct |
1 ms |
2404 KB |
Output is correct |
33 |
Correct |
1 ms |
2404 KB |
Output is correct |
34 |
Correct |
1 ms |
2660 KB |
Output is correct |
35 |
Correct |
1 ms |
2400 KB |
Output is correct |
36 |
Correct |
1 ms |
2404 KB |
Output is correct |
37 |
Correct |
1 ms |
2400 KB |
Output is correct |
38 |
Correct |
1 ms |
2408 KB |
Output is correct |
39 |
Correct |
1 ms |
2408 KB |
Output is correct |
40 |
Correct |
1 ms |
2408 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
27 ms |
15680 KB |
Output is correct |
47 |
Correct |
16 ms |
9820 KB |
Output is correct |
48 |
Correct |
14 ms |
9564 KB |
Output is correct |
49 |
Correct |
15 ms |
9792 KB |
Output is correct |
50 |
Correct |
12 ms |
9308 KB |
Output is correct |
51 |
Correct |
19 ms |
9356 KB |
Output is correct |
52 |
Correct |
8 ms |
5152 KB |
Output is correct |
53 |
Correct |
5 ms |
4956 KB |
Output is correct |
54 |
Correct |
14 ms |
9428 KB |
Output is correct |
55 |
Correct |
15 ms |
9308 KB |
Output is correct |
56 |
Correct |
10 ms |
9192 KB |
Output is correct |
57 |
Correct |
14 ms |
11868 KB |
Output is correct |
58 |
Correct |
13 ms |
11248 KB |
Output is correct |
59 |
Correct |
9 ms |
9308 KB |
Output is correct |
60 |
Correct |
12 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2404 KB |
Output is correct |
31 |
Correct |
2 ms |
2660 KB |
Output is correct |
32 |
Correct |
1 ms |
2404 KB |
Output is correct |
33 |
Correct |
1 ms |
2404 KB |
Output is correct |
34 |
Correct |
1 ms |
2660 KB |
Output is correct |
35 |
Correct |
1 ms |
2400 KB |
Output is correct |
36 |
Correct |
1 ms |
2404 KB |
Output is correct |
37 |
Correct |
1 ms |
2400 KB |
Output is correct |
38 |
Correct |
1 ms |
2408 KB |
Output is correct |
39 |
Correct |
1 ms |
2408 KB |
Output is correct |
40 |
Correct |
1 ms |
2408 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
27 ms |
15680 KB |
Output is correct |
47 |
Correct |
16 ms |
9820 KB |
Output is correct |
48 |
Correct |
14 ms |
9564 KB |
Output is correct |
49 |
Correct |
15 ms |
9792 KB |
Output is correct |
50 |
Correct |
12 ms |
9308 KB |
Output is correct |
51 |
Correct |
19 ms |
9356 KB |
Output is correct |
52 |
Correct |
8 ms |
5152 KB |
Output is correct |
53 |
Correct |
5 ms |
4956 KB |
Output is correct |
54 |
Correct |
14 ms |
9428 KB |
Output is correct |
55 |
Correct |
15 ms |
9308 KB |
Output is correct |
56 |
Correct |
10 ms |
9192 KB |
Output is correct |
57 |
Correct |
14 ms |
11868 KB |
Output is correct |
58 |
Correct |
13 ms |
11248 KB |
Output is correct |
59 |
Correct |
9 ms |
9308 KB |
Output is correct |
60 |
Correct |
12 ms |
9308 KB |
Output is correct |
61 |
Correct |
115 ms |
47188 KB |
Output is correct |
62 |
Correct |
94 ms |
31568 KB |
Output is correct |
63 |
Correct |
76 ms |
21816 KB |
Output is correct |
64 |
Correct |
61 ms |
15872 KB |
Output is correct |
65 |
Correct |
51 ms |
15868 KB |
Output is correct |
66 |
Correct |
76 ms |
15952 KB |
Output is correct |
67 |
Correct |
63 ms |
13868 KB |
Output is correct |
68 |
Correct |
31 ms |
11356 KB |
Output is correct |
69 |
Correct |
64 ms |
15920 KB |
Output is correct |
70 |
Correct |
76 ms |
15984 KB |
Output is correct |
71 |
Correct |
39 ms |
15952 KB |
Output is correct |
72 |
Correct |
73 ms |
28496 KB |
Output is correct |
73 |
Correct |
53 ms |
20560 KB |
Output is correct |
74 |
Correct |
47 ms |
15964 KB |
Output is correct |
75 |
Correct |
48 ms |
16136 KB |
Output is correct |