codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

101A.md (2575B)


      1 Source: https://codeforces.com/problemset/problem/101/A
      2 
      3 A. Homework
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of *n* small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more than *k* characters, it will be very suspicious.
     22 
     23 Find the least number of distinct characters that can remain in the string after no more than *k* characters are deleted. You also have to find any possible way to delete the characters.
     24 
     25 Input
     26 
     27 The first input data line contains a string whose length is equal to *n* (1 ≤ *n* ≤ 105). The string consists of lowercase Latin letters. The second line contains the number *k* (0 ≤ *k* ≤ 105).
     28 
     29 Output
     30 
     31 Print on the first line the only number *m* — the least possible number of different characters that could remain in the given string after it loses no more than *k* characters.
     32 
     33 Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly *m* distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactly *m* distinct characters, print any of them.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 aaaaa  
     41 4
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 1  
     48 aaaaa
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 abacaba  
     55 4
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 1  
     62 aaaa
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 abcdefgh  
     69 10
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 0
     76 ```
     77 
     78 Note
     79 
     80 In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.
     81 
     82 In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a" (as they are no more than four), which will result in the "aaaa" string.
     83 
     84 In the third sample you are given a line whose length is equal to 8, and *k* = 10, so that the whole line can be deleted. The correct answer is 0 and an empty string.