이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
/**
the least number of changes = the most number of heights that do not change
LIS: i1, i2, i3, ...., ik
a[ij]<= ij*M
a[ij+1] <= a[ij] + (ij+1-ij)*M
<=> M*ij - a[ij] >=0
M*ij - a[ij] <= M*(ij+1) - a[ij+1]
<=> make b[i] = M*i - a[i]
then ans = n - length of the longest non-decreasing subsequence of b
**/
using namespace std;
const int maxn=2e5+5,inf=1e18;
int n,m,ans;
int b[maxn],dp[maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=1,x;i<=n;i++) cin>>x,b[i]=m*i-x,dp[i]=inf;
for (int i=1;i<=n;i++)
{
if (b[i]<0) continue;
int pos=upper_bound(dp+1,dp+n+1,b[i])-dp;
ans=max(ans,pos);
dp[pos]=b[i];
}
cout<<n-ans;
}
# | 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... |