Submission #1030351

# Submission time Handle Problem Language Result Execution time Memory
1030351 2024-07-22T03:24:57 Z Luvidi Global Warming (CEOI18_glo) C++17
0 / 100
2000 ms 6976 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back

vector<int> lis(vector<int> a){
    int n=a.size();
    vector<int> ans(n),v;
    for(int i=0;i<n;i++){
        if(v.empty()||v.back()<a[i])v.pb(a[i]);
        else{
            int idx=lower_bound(v.begin(),v.end(),a[i])-v.begin();
            v[idx]=a[i];
        }
        ans[i]=v.size();
    }
    return ans;
}

void solve() {
    int n,x;
    cin>>n>>x;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int> v1=lis(a),v2(n),a2(n);
    for(int i=0;i<n;i++)a2[i]=-a[n-1-i];
    vector<int> t=lis(a2);
    for(int i=0;i<n;i++)v2[i]=t[n-1-i];
    int ans=1;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++)if(a[i]-x<a[j]){
            ans=max(ans,v1[i]+v2[j]);
        }
    }
    cout<<ans;
}

int main() {   
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2033 ms 6976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 2116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 3540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -