Submission #291922

# Submission time Handle Problem Language Result Execution time Memory
291922 2020-09-06T03:16:33 Z ngotienhung Global Warming (CEOI18_glo) C++14
100 / 100
66 ms 4640 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second

using namespace std;

const int maxN = 5e5 + 10;
const int inf = 1e9 + 10;

int n,x;
int a[maxN], ans[maxN], f[maxN];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n >> x;

    f[0] = inf;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        f[i] = inf;
    }

    int res = 0;
    for(int i = 1; i <= n; ++i){
        int it = lower_bound(f, f + n, a[i]) - f;
        f[it] = a[i];
        ans[i] = it + 1;
        res = max(res, ans[i]);
    }

    f[0] = inf;
    for(int i = 1; i <= n; ++i){
        a[i] = -a[i];
        f[i] = inf;
    }

    for(int i = n; i >= 1; --i){
        int it = lower_bound(f, f + n, a[i] + x) - f;
        int it2 = lower_bound(f, f + n, a[i]) - f;
        f[it2] = a[i];
        res = max(res, it + ans[i]);
    }

    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4600 KB Output is correct
2 Correct 65 ms 4600 KB Output is correct
3 Correct 66 ms 4600 KB Output is correct
4 Correct 65 ms 4600 KB Output is correct
5 Correct 51 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1408 KB Output is correct
2 Correct 15 ms 1408 KB Output is correct
3 Correct 19 ms 1408 KB Output is correct
4 Correct 14 ms 1280 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 15 ms 1280 KB Output is correct
7 Correct 13 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2560 KB Output is correct
2 Correct 30 ms 2560 KB Output is correct
3 Correct 59 ms 4600 KB Output is correct
4 Correct 52 ms 3832 KB Output is correct
5 Correct 27 ms 2176 KB Output is correct
6 Correct 44 ms 3836 KB Output is correct
7 Correct 50 ms 4472 KB Output is correct
8 Correct 25 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 65 ms 4600 KB Output is correct
28 Correct 65 ms 4600 KB Output is correct
29 Correct 66 ms 4600 KB Output is correct
30 Correct 65 ms 4600 KB Output is correct
31 Correct 51 ms 3968 KB Output is correct
32 Correct 15 ms 1408 KB Output is correct
33 Correct 15 ms 1408 KB Output is correct
34 Correct 19 ms 1408 KB Output is correct
35 Correct 14 ms 1280 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 15 ms 1280 KB Output is correct
38 Correct 13 ms 1408 KB Output is correct
39 Correct 30 ms 2560 KB Output is correct
40 Correct 30 ms 2560 KB Output is correct
41 Correct 59 ms 4600 KB Output is correct
42 Correct 52 ms 3832 KB Output is correct
43 Correct 27 ms 2176 KB Output is correct
44 Correct 44 ms 3836 KB Output is correct
45 Correct 50 ms 4472 KB Output is correct
46 Correct 25 ms 2560 KB Output is correct
47 Correct 32 ms 2564 KB Output is correct
48 Correct 32 ms 2552 KB Output is correct
49 Correct 64 ms 4604 KB Output is correct
50 Correct 50 ms 3840 KB Output is correct
51 Correct 38 ms 2944 KB Output is correct
52 Correct 51 ms 3964 KB Output is correct
53 Correct 46 ms 3960 KB Output is correct
54 Correct 50 ms 4600 KB Output is correct
55 Correct 55 ms 4640 KB Output is correct