Submission #99571

#TimeUsernameProblemLanguageResultExecution timeMemory
99571MercenaryGlobal Warming (CEOI18_glo)C++14
100 / 100
62 ms4216 KiB
#include<bits/stdc++.h>

using namespace std;
#define taskname "TEST"
#define pb	push_back
#define mp 	make_pair
typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;

int n , x , a[maxn];
int prefix[maxn];

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

int b[maxn];

void solve()
{
    int m = 0;
    for(int i = 1 ; i <= n ; ++i)
    {
        int k = lower_bound(b + 1 , b + m + 1 , a[i]) - b;
        b[k] = a[i];
        m = max(m , k);
        prefix[i] = k;
    }
    int res = 0;
    m = 0;
    for(int i = n ; i >= 1 ; --i)
    {
        res = max(res , min(m , int(lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b) - 1) + prefix[i]);
        int k = lower_bound(b + 1 , b + m + 1 , a[i] + x , greater<int>()) - b;
        b[k] = a[i] + x;
        m = max(m , k);
    }
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    enter();
    solve();
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:51:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin) ,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
glo.cpp:51:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#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...