Home AtCoder. 006 Smallest Subsequence(5)
Post
Cancel

AtCoder. 006 Smallest Subsequence(5)

[Link] https://AtCoder.jp/contests/typical90/tasks/typical90_f


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
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] argA = br.readLine().split("\\s");
    int n = Integer.parseInt(argA[0]);
    int k = Integer.parseInt(argA[1]);
    String s = br.readLine();
    int idx = 0, tempIdx = 0, len = 0;
    char temp = 0;
    while(len != k) {
      temp = s.charAt(idx);
      tempIdx = idx;
      for(; idx <= n - k + len; idx++) {
        if(temp > s.charAt(idx)) {
          temp = s.charAt(idx);
          tempIdx = idx;
        }
      }
      idx = tempIdx + 1;
      lem++;
      sb.append(temp);
    }
    System.out.println(sb);
  }
}
This post is licensed under CC BY 4.0 by the author.