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;
int test;
int n;
int k;
int dp[5005];
pair<int,int> B[5005];
int A[5005];
int main(){
cin >> n;
cin >> k;
for(int i=0; i<n; i++)
{
int v;
cin >> v;
B[i]={v,i};
}
sort(B,B+n);
int group=0;
int cnt=0;
for(int i=0; i<n; i++)
{
A[B[i].second]=group;
cnt++;
if(cnt==k)
{
cnt=0;
group++;
}
}
dp[0]=1;
int maxi;
int ans=0;
for(int i=1; i<n; i++)
{
maxi=i;
for(int j=0; j<i; j++)
{
if(A[j]<=A[i] && dp[j]>dp[maxi])
{
maxi=j;
}
}
dp[i]=dp[maxi]+1;
ans=max(ans,dp[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... |
# | 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... |