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 main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n ; i++)
cin >> v[i];
vector<int> sortedv = v;
sort(sortedv.begin(), sortedv.end());
for (int i = 0; i < n / k; i++) {
set<int> s;
for (int j = 0; j < k; j++) {
s.insert(sortedv[i * k + j]);
}
int p = 0;
for (int j = 0; j < n; j++) {
if (s.count(v[j])) {
v[j] = sortedv[i * k + p];
p++;
}
}
}
vector<int> dp(n, 1);
int longest = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (v[i] > v[j]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
longest = max(longest, dp[i]);
}
cout << n - longest;
}
# | 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... |