This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 998244353;
#define fo(i,e) for(ll i = 0; i < e; i++)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 2e9
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int maxn = 5001;
void solve(){
int n,k;cin >> n >> k;
vector<int> srt, arr;
unordered_map<int,int> mp;
fo(i,n){
int tmep ;
cin >> tmep;
arr.pb(tmep);
}
srt = arr;
sort(srt.begin(), srt.end());
for(int i = 0 ; i<n ; i+=k) for(int j = 0; j<k; ++j) mp[srt[i+j]] = i;
fo(i,n){arr[i] = mp[arr[i]];}
int ans = 1;
int dp[n];
dp[0] =1;
for(int i = 1 ; i<n ; ++i){
dp[i] = 1;
for(int j = i-1; j>=0; --j){
if(arr[j]<=arr[i])
dp[i] = max(dp[i], dp[j]+1);
}
ans = max(ans, dp[i]);
}
cout << n-ans;
}
int main(){
fast_cin();
ll t=1;
//cin >> t;
for(int it=1;it<=t;it++) {
solve();
}
return 0;
}
# | 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... |