题意:给你n个数字让你从这n个数字当中删除m个,使得最后得到的数字的大小最大。
思路:贪心即可,从前面仅可能选择最大的数字。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define MAXN 200000
#define MAXE 210
#define INF 10000000
#define MOD 1000000007
#define LL long long
#define PI acos(-1.0)
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0)
break;
string str;
cin >> str;
string order_str = "\0";
int pos = 0;
char max_char = 0;
for (int i = 0; i + m < n; i = pos + 1) {
if (m == 0) {
break;
}
max_char = str[i];
pos = i;
for (int j = i; j <= i + m && j < n; ++j) {
if (str[j] > max_char) {
max_char = str[j];
pos = j;
}
}
m -= (pos - i);
order_str += max_char;
}
if (m == 0) {
for (int i = pos + 1; i < n; ++i) {
order_str += str[i];
}
}
cout << order_str << endl;
}
return 0;
}
/*
4 2
3759
6 3
123123
7 4
1000000
0 0
*/