Submission #395843

# Submission time Handle Problem Language Result Execution time Memory
395843 2021-04-29T03:41:02 Z Pichon5 Global Warming (CEOI18_glo) C++17
100 / 100
128 ms 5264 KB
#include<bits/stdc++.h>
#include <chrono>
#include <thread>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
//salida rapida "\n"
//DECIMALES fixed<<sp(n)<<x<<endl;
//gcd(a,b)= ax + by
//lCB x&-x
//set.erase(it) - ersases the element present at the required index//auto it = s.find(element)
//set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end()
//set.lower_bound(element) - iterator pointing to element greater than or equal to the given element
//set.upper_bound(element) - iterator pointing to element greater than the given element
// | ^
//__builtin_popcount(x)
using namespace std;
const ll INF=1e16;
int main()
{
    //freopen("glo6a.in","r",stdin);
    ll n,k,x;
    cin>>n>>k;
    vll v;
    ll res=0;
    for(int i=0;i<n;i++){
        cin>>x;
        v.pb(x);
    }
    vll E(n+1);
    vll dp(n+2,INF);
    dp[0]=-INF;
    for(int i=0;i<n;i++){
        int b=1,e=n;
        while(b<=e){
            ll mid=(b+e)/2;
            if(v[i]<=dp[mid] && dp[mid-1]<v[i]){
                dp[mid]=v[i];
                //cout<<v[i]<<" menor a "<<dp[mid]<<"  -  "<<dp[i-1]
                res=max(res,mid);
                E[i]=mid;break;
            }
            if(dp[mid]>v[i]){
                e=mid-1;
            }else{
                b=mid+1;
            }
        }
    }
    dp.assign(n+2,INF);
    dp[0]=-INF;
    for(int i=n-1;i>=0;i--){
        int b=1,e=n;
        int val=-v[i]+k;//le reduzco a todo el prefijo i, eso es darle ventaja a i sobre el sufijo
        while(b<=e){
            int mid=(b+e)/2;
            if(val<dp[mid] && dp[mid-1]<val){
                res=max(res,E[i]+mid-1);
                break;
            }
            if(dp[mid]>val){
                e=mid-1;
            }else{
                b=mid+1;
            }
        }
        val=-v[i];
        b=1,e=n;
        while(b<=e){
            int mid=(b+e)/2;
            if(val<dp[mid] && dp[mid-1]<val){
                dp[mid]=val;
                break;
            }
            if(dp[mid]>val){
                e=mid-1;
            }else{
                b=mid+1;
            }
        }

    }
    cout<<res<<endl;



    return 0;
}
//409336628
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 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 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 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 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 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 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 5140 KB Output is correct
2 Correct 124 ms 5036 KB Output is correct
3 Correct 128 ms 5080 KB Output is correct
4 Correct 125 ms 5084 KB Output is correct
5 Correct 88 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1488 KB Output is correct
2 Correct 31 ms 1604 KB Output is correct
3 Correct 31 ms 1588 KB Output is correct
4 Correct 22 ms 1616 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 22 ms 1492 KB Output is correct
7 Correct 34 ms 1500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 2744 KB Output is correct
2 Correct 61 ms 2748 KB Output is correct
3 Correct 116 ms 5100 KB Output is correct
4 Correct 89 ms 5116 KB Output is correct
5 Correct 51 ms 2764 KB Output is correct
6 Correct 83 ms 4856 KB Output is correct
7 Correct 104 ms 4884 KB Output is correct
8 Correct 56 ms 2868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 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 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 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 2 ms 204 KB Output is correct
27 Correct 123 ms 5140 KB Output is correct
28 Correct 124 ms 5036 KB Output is correct
29 Correct 128 ms 5080 KB Output is correct
30 Correct 125 ms 5084 KB Output is correct
31 Correct 88 ms 5072 KB Output is correct
32 Correct 30 ms 1488 KB Output is correct
33 Correct 31 ms 1604 KB Output is correct
34 Correct 31 ms 1588 KB Output is correct
35 Correct 22 ms 1616 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 22 ms 1492 KB Output is correct
38 Correct 34 ms 1500 KB Output is correct
39 Correct 58 ms 2744 KB Output is correct
40 Correct 61 ms 2748 KB Output is correct
41 Correct 116 ms 5100 KB Output is correct
42 Correct 89 ms 5116 KB Output is correct
43 Correct 51 ms 2764 KB Output is correct
44 Correct 83 ms 4856 KB Output is correct
45 Correct 104 ms 4884 KB Output is correct
46 Correct 56 ms 2868 KB Output is correct
47 Correct 61 ms 2732 KB Output is correct
48 Correct 61 ms 2704 KB Output is correct
49 Correct 124 ms 5104 KB Output is correct
50 Correct 96 ms 5264 KB Output is correct
51 Correct 70 ms 3888 KB Output is correct
52 Correct 91 ms 5112 KB Output is correct
53 Correct 86 ms 5040 KB Output is correct
54 Correct 110 ms 5096 KB Output is correct
55 Correct 115 ms 5120 KB Output is correct