Submission #260703

#TimeUsernameProblemLanguageResultExecution timeMemory
260703biggGlobal Warming (CEOI18_glo)C++14
100 / 100
85 ms7800 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 10;
const ll INF =1e18;
ll dp[MAXN], v[MAXN], neg[MAXN];
int ans1[MAXN];
int main(){
	int n;
	ll x;
	scanf("%d %lld", &n, &x);
	for(int i = 1; i <= n; i++) scanf("%lld", &v[i]), dp[i] = INF, neg[i] = -v[i];
	//dp[0] = INF;
	int ans = -1;
	for(int i = 0; i <= n; i++) dp[i] = INF;
		for(int i = 1; i <= n; i++){
			int it1 = lower_bound(dp, dp + n, v[i]) - dp;
			dp[it1] = v[i];
			ans1[i] = it1 +1;
			ans = max(ans, it1 + 1);
	}
	
	for(int i = 0; i <= n; i++) dp[i] = INF;
	for(int i = n; i; i--){
		int it1 = lower_bound(dp, dp + n, neg[i] +x) - dp;
		int it2 = lower_bound(dp, dp + n, neg[i]) - dp;
		dp[it2] = neg[i];
		ans = max(ans, it1 + ans1[i]);
		//printf("%d\n", it1 + ans1[i]);
	}
	
	
	printf("%d\n",ans );
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %lld", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~~~
glo.cpp:12:63: 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("%lld", &v[i]), dp[i] = INF, neg[i] = -v[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...