#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define file freopen("in.txt", "r", stdin);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define keepunique(v) (v).erase(unique(all(v)),v.end())
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);
const int maxn = 5005;
ll inf = 1e17;
map<ll, ll>mark;
ll arr[maxn];
vector<ll>vec;
int n, k;
int lis(){
int ans = 0;
ll t[n+1];
t[0] = -inf;
for(int i=1; i<=n; i++)t[i] = inf;
for(int i=0; i<n; i++){
int hi = ans, lo = 0;
while(lo <= hi){
int mid = (lo+hi)>>1;
if(t[mid] <= mark[arr[i]])lo = mid+1;
else hi = mid-1;
}
t[lo]=mark[arr[i]];
ans = max(ans, lo);
}
return ans;
}
int main(){
//file
fastread
cin>>n>>k;
for(int i=0; i<n; i++){
cin>>arr[i];
vec.pb(arr[i]);
}
sort(all(vec));
int cnt = 0;
for(int i=0; i<n; i++){
if(i%k == 0)++cnt;
mark[vec[i]]=cnt;
}
cout<<n-lis()<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
616 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1108 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1196 KB |
Output is correct |
2 |
Correct |
7 ms |
1264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1296 KB |
Output is correct |
2 |
Correct |
7 ms |
1348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1404 KB |
Output is correct |
2 |
Correct |
8 ms |
1456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1520 KB |
Output is correct |
2 |
Correct |
8 ms |
1564 KB |
Output is correct |