#include <bits/stdc++.h>
using namespace std;
const int nx=5e3+5;
int n, k, v[nx], t, l[nx], r[nx], g, res=INT_MAX, dp[nx];
map<int, int> mp;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
g=n/k;
for (int i=1; i<=n; i++) cin>>v[i], mp[-v[i]]=0, l[i]=INT_MAX, r[i]=0;
for (auto &[x, y]:mp) y=(t/k)+1, t++;
for (int i=1; i<=n; i++) v[i]=mp[-v[i]], l[v[i]]=min(l[v[i]], i), r[v[i]]=max(r[v[i]], i);
for (int i=1; i<=g; i++)
{
dp[i]=i;
if (i>1&&r[i]<l[i-1]) dp[i]=dp[i-1];
//cout<<"dp "<<i<<' '<<dp[i]<<'\n';
int cur=(n-(i-dp[i]+1)*k);
for (int j=r[dp[i]]+1; j<=n; j++) if (v[j]==dp[i]-1) cur--;
for (int j=1; j<l[i]; j++) if (v[j]==i+1) cur--;
res=min(res, cur);
}
cout<<res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |