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() {
int n, k;
cin >> n >> k;
vector <int> nums(n), id(n);
vector <int> nums2(n);
map <int, int> pos;
for (int i = 0; i < n; i++) {
cin >> nums[i];
nums2[i] = nums[i];
pos[nums[i]] = i;
}
sort(nums2.begin(), nums2.end());
for (int i = 0, pt = 0; i < n; i++) {
if (i % k == 0)
pt++;
id[pos[nums2[i]]] = pt;
}
vector <int> dp;
for (int i = 0; i < n; i++) {
auto it = upper_bound(dp.begin(), dp.end(), id[i]);
if (it == dp.end())
dp.push_back(id[i]);
else
*it = id[i];
}
cout << n - (int)dp.size() << '\n';
}
# | 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... |