-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathURI1084ErasingAndWinning.java
More file actions
50 lines (44 loc) · 1.45 KB
/
URI1084ErasingAndWinning.java
File metadata and controls
50 lines (44 loc) · 1.45 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
/**
* See
* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1084">Erasing and Winning</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class URI1084ErasingAndWinning {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String l;
int N, D, t;
String[] aux;
char[] numbers;
char current;
while (!(l = in.readLine()).equals("0 0")) {
aux = l.split("\\s");
N = Integer.parseInt(aux[0]);
D = Integer.parseInt(aux[1]);
Stack<Character> stack = new Stack<>();
numbers = in.readLine().toCharArray();
t = N - D;
for (int i = 0; i < N; i++) {
current = numbers[i];
while (stack.size() > 0 && stack.size() + N - i > t && stack.lastElement() < current) {
stack.pop();
}
if (stack.size() < t) {
stack.push(current);
}
}
for (char number : stack) {
out.print(number);
}
out.println();
}
out.close();
}
}