Submission #716599

#TimeUsernameProblemLanguageResultExecution timeMemory
716599nononoGlobal Warming (CEOI18_glo)C++17
100 / 100
119 ms4220 KiB
#include "bits/stdc++.h"
#define SZ(x) (int)(x.size())
using namespace std;

const int mxN = 2e5 + 10;
int n, x, a[mxN];
int dp[mxN];

signed main(){

    #define file "test"
    if(fopen(file".inp", "r")){
        freopen(file".inp", "r", stdin);
        freopen(file".out", "w", stdout);
    }

    ios_base::sync_with_stdio();
    cin.tie(); cout.tie();

    cin >> n >> x;

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

    vector<int> f;

    for(int i = 1; i <= n; i ++){
        int pos = lower_bound(f.begin(), f.end(), a[i]) - f.begin();
        if(pos == SZ(f)) f.push_back(a[i]);
        f[pos] = a[i];
        dp[i] = pos + 1;
    }

    f.clear();

    int res = 0;
    for(int i = n; i >= 1; i --){
        int pos = lower_bound(f.begin(), f.end(), - a[i] + x) - f.begin();
        res = max(res, dp[i] + pos);

        pos = lower_bound(f.begin(), f.end(), - a[i]) - f.begin();
        if(pos == SZ(f)) f.push_back(- a[i]);
        f[pos] = - a[i];
    }

    cout << max(res, dp[n]) << "\n";
    return 0;
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen(file".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen(file".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...