답안 #804544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804544 2023-08-03T09:42:18 Z Valaki2 Global Warming (CEOI18_glo) C++14
100 / 100
63 ms 7792 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back

const int maxn = 2e5;

int n, x;
int v[1 + maxn];
int pref[1 + maxn], suff[1 + maxn];

void solve() {
    cin >> n >> x;
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    vector<int> d;
    for(int i = 1; i <= n; i++) {
        auto other_it = lower_bound(d.begin(), d.end(), v[i] + x);
        pref[i] = other_it - d.begin();
        auto it = lower_bound(d.begin(), d.end(), v[i]);
        if(it == d.end()) {
            d.pb(v[i]);
        } else {
            *it = min(*it, v[i]);
        }
    }
    d.clear();
    for(int i = 1; i <= n; i++) {
        v[i] = -v[i];
    }
    for(int i = n; i >= 1; i--) {
        auto other_it = lower_bound(d.begin(), d.end(), v[i]);
        suff[i] = other_it - d.begin();
        auto it = lower_bound(d.begin(), d.end(), v[i]);
        if(it == d.end()) {
            d.pb(v[i]);
        } else {
            *it = min(*it, v[i]);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans = max(ans, pref[i] + suff[i] + 1);
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 6836 KB Output is correct
2 Correct 54 ms 6824 KB Output is correct
3 Correct 54 ms 6920 KB Output is correct
4 Correct 55 ms 6924 KB Output is correct
5 Correct 27 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2008 KB Output is correct
2 Correct 13 ms 1956 KB Output is correct
3 Correct 14 ms 2016 KB Output is correct
4 Correct 7 ms 2032 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 2136 KB Output is correct
7 Correct 10 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3576 KB Output is correct
2 Correct 24 ms 3548 KB Output is correct
3 Correct 54 ms 6864 KB Output is correct
4 Correct 27 ms 7096 KB Output is correct
5 Correct 13 ms 3796 KB Output is correct
6 Correct 23 ms 6796 KB Output is correct
7 Correct 28 ms 7500 KB Output is correct
8 Correct 20 ms 3660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 63 ms 6836 KB Output is correct
28 Correct 54 ms 6824 KB Output is correct
29 Correct 54 ms 6920 KB Output is correct
30 Correct 55 ms 6924 KB Output is correct
31 Correct 27 ms 6996 KB Output is correct
32 Correct 14 ms 2008 KB Output is correct
33 Correct 13 ms 1956 KB Output is correct
34 Correct 14 ms 2016 KB Output is correct
35 Correct 7 ms 2032 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 7 ms 2136 KB Output is correct
38 Correct 10 ms 1912 KB Output is correct
39 Correct 26 ms 3576 KB Output is correct
40 Correct 24 ms 3548 KB Output is correct
41 Correct 54 ms 6864 KB Output is correct
42 Correct 27 ms 7096 KB Output is correct
43 Correct 13 ms 3796 KB Output is correct
44 Correct 23 ms 6796 KB Output is correct
45 Correct 28 ms 7500 KB Output is correct
46 Correct 20 ms 3660 KB Output is correct
47 Correct 29 ms 3652 KB Output is correct
48 Correct 32 ms 3548 KB Output is correct
49 Correct 55 ms 6932 KB Output is correct
50 Correct 29 ms 7068 KB Output is correct
51 Correct 28 ms 5628 KB Output is correct
52 Correct 35 ms 7084 KB Output is correct
53 Correct 33 ms 7124 KB Output is correct
54 Correct 34 ms 7792 KB Output is correct
55 Correct 42 ms 6900 KB Output is correct