Submission #422657

# Submission time Handle Problem Language Result Execution time Memory
422657 2021-06-10T09:36:37 Z snasibov05 Global Warming (CEOI18_glo) C++14
100 / 100
138 ms 2628 KB
#include <bits/stdc++.h>

using namespace std;

#define oo 1000000000

int main() {
    int n, x; cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    int sz = 1;
    vector<int> dp(n);
    vector<int> c(n+1, oo);
    c[0] = 0;
    c[1] = v[0];
    dp[0] = 1;

    for (int i = 1; i < n; ++i) {
        if (v[i] < c[1]) c[1] = v[i], dp[i] = 1;
        else if (v[i] > c[sz]) c[sz+1] = v[i], dp[i] = ++sz;
        else {
            int k = lower_bound(c.begin(), c.end(), v[i]) - c.begin();
            c[k] = v[i];
            dp[i] = k;
        }
    }

    int ans = dp[n-1];
    c.assign(n+1, 0);
    c[0] = oo + oo;
    c[1] = v[n-1] + x;
    dp[n-1] = 1;
    sz = 1;

    for (int i = n-2; i >= 0; --i){
        if (v[i] > c[1]) ans = max(ans, dp[i]);
        else if (v[i] < c[sz]) ans = max(ans, dp[i] + sz);
        else{
            int k = upper_bound(c.rbegin(), c.rend(), v[i]) - c.rbegin();
            k = n - k;
            ans = max(ans, dp[i] + k);
        }

        if (v[i] + x > c[1]) c[1] = v[i] + x;
        else if (v[i] + x < c[sz]) c[++sz] = v[i] + x;
        else{
            int k = upper_bound(c.rbegin(), c.rend(), v[i] + x) - c.rbegin();
            k = n - k + 1;
            c[k] = v[i] + x;
        }
    }

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 2604 KB Output is correct
2 Correct 134 ms 2628 KB Output is correct
3 Correct 127 ms 2600 KB Output is correct
4 Correct 129 ms 2604 KB Output is correct
5 Correct 77 ms 2608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 884 KB Output is correct
2 Correct 31 ms 880 KB Output is correct
3 Correct 36 ms 868 KB Output is correct
4 Correct 19 ms 888 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 19 ms 892 KB Output is correct
7 Correct 28 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 1440 KB Output is correct
2 Correct 57 ms 1440 KB Output is correct
3 Correct 121 ms 2620 KB Output is correct
4 Correct 71 ms 2608 KB Output is correct
5 Correct 38 ms 1348 KB Output is correct
6 Correct 83 ms 2444 KB Output is correct
7 Correct 85 ms 2440 KB Output is correct
8 Correct 55 ms 1456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 127 ms 2604 KB Output is correct
28 Correct 134 ms 2628 KB Output is correct
29 Correct 127 ms 2600 KB Output is correct
30 Correct 129 ms 2604 KB Output is correct
31 Correct 77 ms 2608 KB Output is correct
32 Correct 33 ms 884 KB Output is correct
33 Correct 31 ms 880 KB Output is correct
34 Correct 36 ms 868 KB Output is correct
35 Correct 19 ms 888 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 19 ms 892 KB Output is correct
38 Correct 28 ms 876 KB Output is correct
39 Correct 58 ms 1440 KB Output is correct
40 Correct 57 ms 1440 KB Output is correct
41 Correct 121 ms 2620 KB Output is correct
42 Correct 71 ms 2608 KB Output is correct
43 Correct 38 ms 1348 KB Output is correct
44 Correct 83 ms 2444 KB Output is correct
45 Correct 85 ms 2440 KB Output is correct
46 Correct 55 ms 1456 KB Output is correct
47 Correct 64 ms 1444 KB Output is correct
48 Correct 61 ms 1436 KB Output is correct
49 Correct 138 ms 2608 KB Output is correct
50 Correct 78 ms 2628 KB Output is correct
51 Correct 54 ms 2028 KB Output is correct
52 Correct 77 ms 2612 KB Output is correct
53 Correct 66 ms 2628 KB Output is correct
54 Correct 88 ms 2600 KB Output is correct
55 Correct 112 ms 2616 KB Output is correct