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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
//#include "gondola.h"
using namespace std;
#define MAXN 5005
int main() {
int n, k;
cin >> n >> k;
vector<int> order;
vector<int> groups;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
groups.push_back(temp);
order.push_back(temp);
}
sort(groups.begin(), groups.end());
map<int, int> g;
for(int i = 0; i < n; i++){
g[groups[i]] = i / k;
}
for (int i = 0; i < n; i++) {
order[i] = g[order[i]];
}
int dp[MAXN];
int ans = 0;
for (int i = 0; i < n; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
int temp = 0;
if (order[i] >= order[j]) {
temp = 1;
}
else {
continue;
}
dp[i] = max(dp[i], dp[j] + temp);
}
ans = max(ans, dp[i]);
}
cout << n-ans << endl;
}
# | 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... |