Submission #173470

# Submission time Handle Problem Language Result Execution time Memory
173470 2020-01-04T08:31:56 Z emil_physmath Bigger segments (IZhO19_segments) C++17
100 / 100
125 ms 18680 KB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef double ldouble;
typedef long long llong;
typedef unsigned int uint;
typedef pair<int, llong> Dp;

template<typename T1, typename T2>
inline ostream& operator<<(ostream& str, const pair<T1, T2>& p)
{
    return str << "{" << p.first << ", " << p.second << "}";
}
inline const Dp& BestDp(const Dp& a, const Dp& b)
{
    if (a.first == b.first) return a.second < b.second ? a : b;
    return a.first > b.first ? a : b;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x: a)
        cin >> x;
    vector<llong> pref(n);
    for (int i = 0; i < n; ++i)
        pref[i] = a[i] + (i ? pref[i - 1] : 0);
    vector<Dp> dp(n);
    for (int i = 0; i < n; ++i)
        dp[i] = {1, pref[i]};
    for (int i = 0; i + 1 < n; ++i)
    {
        dp[i + 1] = BestDp(dp[i + 1], {dp[i].first, dp[i].second + a[i + 1]});
        int j = -1;
        int l = i + 1, r = n - 1;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (pref[m] - pref[i] >= dp[i].second)
            {
                j = m;
                r = m - 1;
            }
            else
                l = m + 1;
        }
        if (j != -1)
        {
            dp[j] = BestDp(dp[j], {dp[i].first + 1, pref[j] - pref[i]});
            // cerr << "i: " << i << "; " << "j: " << j << "\t" << dp[j] << endl;
        }
    }
    /*for (int i = 0; i < dp.size(); ++i)
        cerr << "dp[" << i << "] = " << dp[i] << endl;*/
    cout << max_element(dp.begin(), dp.end())->first << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 1 ms 504 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 1 ms 504 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 17 ms 3320 KB Output is correct
47 Correct 22 ms 3320 KB Output is correct
48 Correct 23 ms 3348 KB Output is correct
49 Correct 23 ms 3444 KB Output is correct
50 Correct 22 ms 3320 KB Output is correct
51 Correct 25 ms 3448 KB Output is correct
52 Correct 14 ms 2040 KB Output is correct
53 Correct 9 ms 1400 KB Output is correct
54 Correct 19 ms 3344 KB Output is correct
55 Correct 26 ms 3320 KB Output is correct
56 Correct 19 ms 3320 KB Output is correct
57 Correct 18 ms 3320 KB Output is correct
58 Correct 20 ms 3292 KB Output is correct
59 Correct 19 ms 3448 KB Output is correct
60 Correct 19 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 1 ms 504 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 17 ms 3320 KB Output is correct
47 Correct 22 ms 3320 KB Output is correct
48 Correct 23 ms 3348 KB Output is correct
49 Correct 23 ms 3444 KB Output is correct
50 Correct 22 ms 3320 KB Output is correct
51 Correct 25 ms 3448 KB Output is correct
52 Correct 14 ms 2040 KB Output is correct
53 Correct 9 ms 1400 KB Output is correct
54 Correct 19 ms 3344 KB Output is correct
55 Correct 26 ms 3320 KB Output is correct
56 Correct 19 ms 3320 KB Output is correct
57 Correct 18 ms 3320 KB Output is correct
58 Correct 20 ms 3292 KB Output is correct
59 Correct 19 ms 3448 KB Output is correct
60 Correct 19 ms 3320 KB Output is correct
61 Correct 80 ms 15836 KB Output is correct
62 Correct 92 ms 15992 KB Output is correct
63 Correct 106 ms 14400 KB Output is correct
64 Correct 111 ms 14888 KB Output is correct
65 Correct 108 ms 18680 KB Output is correct
66 Correct 125 ms 17400 KB Output is correct
67 Correct 100 ms 13312 KB Output is correct
68 Correct 51 ms 7672 KB Output is correct
69 Correct 94 ms 15096 KB Output is correct
70 Correct 114 ms 16300 KB Output is correct
71 Correct 81 ms 15736 KB Output is correct
72 Correct 94 ms 16376 KB Output is correct
73 Correct 93 ms 16760 KB Output is correct
74 Correct 95 ms 17400 KB Output is correct
75 Correct 95 ms 17136 KB Output is correct