Submission #148092

#TimeUsernameProblemLanguageResultExecution timeMemory
148092WhipppedCreamGlobal Warming (CEOI18_glo)C++17
100 / 100
102 ms4988 KiB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

int n, x;
const int maxn = 2e5+5;
int arr[maxn];
int L[maxn];
int lis[maxn];
int lds[maxn];

int main()
{
	scanf("%d %d", &n, &x);
	for(int i = 1; i<= n; i++) scanf("%d", arr+i);
	int cur = 0;
	for(int i = n; i>= 1; i--)
	{
		int tmp = lower_bound(L, L+cur, -arr[i])-L;
		L[tmp] = -arr[i];
		cur = max(cur, tmp+1);
		lds[i] = tmp+1;
	}
	cur = 0;
	int best = 0;
	for(int i = 1; i<= n; i++)
	{
		best = max(best, lds[i]+(int) (lower_bound(L, L+cur, arr[i]+x)-L));
		int tmp = lower_bound(L, L+cur, arr[i])-L;
		L[tmp] = arr[i];
		cur = max(cur, tmp+1);
		lis[i] = cur;
		//printf("%d: %d\n", i, best);
	}
	best = max(best, lis[n]);
	printf("%d\n", best);
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:19:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i<= n; i++) scanf("%d", arr+i);
                             ~~~~~^~~~~~~~~~~~~
#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...