codeforces-scrape

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

462B.md (1316B)


      1 Source: https://codeforces.com/problemset/problem/462/B
      2 
      3 B. Appleman and Card Game
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
     22 
     23 Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
     24 
     25 Input
     26 
     27 The first line contains two integers *n* and *k* (1 ≤ *k* ≤ *n* ≤ 105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
     28 
     29 Output
     30 
     31 Print a single integer – the answer to the problem.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 15 10  
     39 DZFDFZDFDDDDDDF
     40 ```
     41 
     42 Output
     43 
     44 ```
     45 82
     46 ```
     47 
     48 Input
     49 
     50 ```
     51 6 4  
     52 YJSNPI
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 4
     59 ```
     60 
     61 Note
     62 
     63 In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.