-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path1084.cpp
More file actions
32 lines (32 loc) · 882 Bytes
/
Copy path1084.cpp
File metadata and controls
32 lines (32 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Ivan Carvalho
// Solution to https://www.beecrowd.com.br/judge/problems/view/1084
#include <cstdio>
#include <stack>
using namespace std;
int main() {
int n, m, apagados;
while (scanf("%d %d", &n, &m) && (n || m)) {
getchar();
apagados = 0;
stack<char> pilha, resposta;
for (int i = 0; i < n; i++) {
char davez;
scanf("%c", &davez);
while (!pilha.empty() && apagados < m && davez > pilha.top()) {
pilha.pop();
apagados++;
}
if (pilha.size() < n - m) pilha.push(davez);
}
while (!pilha.empty()) {
resposta.push(pilha.top());
pilha.pop();
}
while (!resposta.empty()) {
printf("%c", resposta.top());
resposta.pop();
}
printf("\n");
}
return 0;
}