This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 2e9 + 7;
int n, x;
int v[MAXN];
int dp[MAXN];
int maxiPos[MAXN], maxiNeg[MAXN];
int ans;
void bt(int cur, int sum);
int main(){
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%d", &v[i]);
if(x == 1e9){
for(int j = 1; j <= n; j++)
dp[j] = INF;
for(int i = 1; i <= n; i++){
int k = lower_bound(dp, dp + 1 + n, v[i]) - dp;
dp[k] = v[i];
maxiPos[i] = max(maxiPos[i - 1], k);
ans = max(ans, k);
}
for(int j = 1; j <= n; j++)
dp[j] = INF;
dp[0] = -INF;
for(int i = n; i > 0; i--){
int k = lower_bound(dp, dp + 1 + n, -v[i]) - dp;
dp[k] = -v[i];
maxiNeg[i] = max(maxiNeg[i + 1], k);
ans = max(ans, k);
ans = max(ans, maxiPos[i] + maxiNeg[i + 1]);
}
printf("%d\n", ans);
return 0;
}
if(x == 0){
for(int j = 1; j <= n; j++)
dp[j] = INF;
for(int i = 1; i <= n; i++){
int k = lower_bound(dp, dp + 1 + n, v[i]) - dp;
dp[k] = v[i];
ans = max(ans, k);
}
printf("%d\n", ans);
return 0;
}
for(int i = n; i > 0; i--){
for(int j = 1; j <= n; j++)
dp[j] = INF;
for(int j = 1; j <= n; j++){
int k = lower_bound(dp, dp + 1 + n, v[j]) - dp;
dp[k] = v[j];
ans = max(ans, k);
}
v[i] += x;
}
printf("%d\n", ans);
}
void bt(int cur, int sum){
for(int i = 1; i <= n; i++)
dp[i] = INF;
for(int i = 1; i <= n; i++){
int k = lower_bound(dp, dp + 1 + n, v[i]) - dp;
dp[k] = v[i];
ans = max(ans, k);
}
if(cur == n) return;
v[cur + 1] += sum;
bt(cur + 1, sum);
v[cur + 1] -= sum;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:16: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:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &v[i]);
~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |