#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 |
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 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
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 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
592 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
592 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
592 KB |
Output is correct |
2 |
Correct |
5 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
592 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |