Submission #361648

# Submission time Handle Problem Language Result Execution time Memory
361648 2021-01-30T23:56:59 Z iliccmarko Global Warming (CEOI18_glo) C++14
100 / 100
74 ms 7148 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 2e5 + 5;
ll a[N], dp[N], levo[N], desno[N];
ll n, x;



int main()
{
    ios
    cin>>n>>x;
    for(ll i = 0;i<n;i++) cin>>a[i];
    for(ll i = 0;i<N;i++) dp[i] = LINF;
    for(ll i = 0;i<n;i++)
    {
        ll pos = lower_bound(dp, dp+n+1, a[i]+x) - dp;
        levo[i] = pos-1;
        pos =  lower_bound(dp+1, dp+n+1, a[i]) - dp;
        //cout<<pos<<endl;
        dp[pos] = a[i];
    }
    for(int i = 0;i<N;i++) dp[i] = LINF;
    ll ans = 0;
    for(int i = n-1;i>=0;i--)
    {
        ll pos = lower_bound(dp+1, dp+n+1, -a[i]) - dp;
        dp[pos] = -a[i];
        //cout<<levo[i]<<" "<<pos<<endl;
        ans = max(ans, levo[i]+pos);
    }

    cout<<ans;





    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 1 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 1 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 1 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 1 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 1 ms 1900 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 2 ms 1900 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 1900 KB Output is correct
24 Correct 2 ms 1948 KB Output is correct
25 Correct 2 ms 1900 KB Output is correct
26 Correct 2 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 5104 KB Output is correct
2 Correct 65 ms 5100 KB Output is correct
3 Correct 63 ms 5100 KB Output is correct
4 Correct 74 ms 5100 KB Output is correct
5 Correct 48 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2668 KB Output is correct
2 Correct 17 ms 2668 KB Output is correct
3 Correct 15 ms 2668 KB Output is correct
4 Correct 13 ms 2668 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 13 ms 2668 KB Output is correct
7 Correct 14 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3436 KB Output is correct
2 Correct 29 ms 4460 KB Output is correct
3 Correct 59 ms 7148 KB Output is correct
4 Correct 55 ms 6252 KB Output is correct
5 Correct 30 ms 4076 KB Output is correct
6 Correct 45 ms 6124 KB Output is correct
7 Correct 51 ms 6764 KB Output is correct
8 Correct 25 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 1 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 2 ms 1920 KB Output is correct
18 Correct 1 ms 1900 KB Output is correct
19 Correct 2 ms 1900 KB Output is correct
20 Correct 2 ms 1900 KB Output is correct
21 Correct 2 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 1900 KB Output is correct
24 Correct 2 ms 1948 KB Output is correct
25 Correct 2 ms 1900 KB Output is correct
26 Correct 2 ms 1900 KB Output is correct
27 Correct 64 ms 5104 KB Output is correct
28 Correct 65 ms 5100 KB Output is correct
29 Correct 63 ms 5100 KB Output is correct
30 Correct 74 ms 5100 KB Output is correct
31 Correct 48 ms 5100 KB Output is correct
32 Correct 16 ms 2668 KB Output is correct
33 Correct 17 ms 2668 KB Output is correct
34 Correct 15 ms 2668 KB Output is correct
35 Correct 13 ms 2668 KB Output is correct
36 Correct 1 ms 1900 KB Output is correct
37 Correct 13 ms 2668 KB Output is correct
38 Correct 14 ms 2796 KB Output is correct
39 Correct 29 ms 3436 KB Output is correct
40 Correct 29 ms 4460 KB Output is correct
41 Correct 59 ms 7148 KB Output is correct
42 Correct 55 ms 6252 KB Output is correct
43 Correct 30 ms 4076 KB Output is correct
44 Correct 45 ms 6124 KB Output is correct
45 Correct 51 ms 6764 KB Output is correct
46 Correct 25 ms 4460 KB Output is correct
47 Correct 32 ms 4460 KB Output is correct
48 Correct 32 ms 4460 KB Output is correct
49 Correct 64 ms 7020 KB Output is correct
50 Correct 48 ms 6252 KB Output is correct
51 Correct 39 ms 5100 KB Output is correct
52 Correct 50 ms 6380 KB Output is correct
53 Correct 46 ms 6252 KB Output is correct
54 Correct 50 ms 7020 KB Output is correct
55 Correct 54 ms 7020 KB Output is correct