Submit | All submissions | Best solutions | Back to list |
ACMPRAC2 - Entrée |
Master Bates is a ravenous eater; due to his monstrous eating habits he is having some difficulties in performing. Dr. XXX has asked him to cut down on his intake. The doctor has prescribed the number of meals he can have in a day. Now Bates has got ‘k’ different varieties of foods (1 <= k <= 26) and he can have at most ‘m’ meals in a day (1 <= m <= 100) as prescribed by the doctor. Each variety of food is specified by a letter of the alphabet in lower case. A meal is defined as a string of contiguous characters of same type i.e. all the characters in the substring should be the same. Master Bates wants to eat as much as possible in his ‘m’ meals. Assuming each letter is 1 unit of food. What is the maximum amount he can consume?
Input
First line of input is the number of test cases (not more than 100). Each test case consists of 2 lines, first line of each case consists of an integer m (1 <= m <= 100).
Second line of each case consists of a string describing the food that he has for the day. There will be at most 100000 (10^5) characters in the string.
Output
Output one integer indicating the maximum amount of food he can consume.
Example
Input: 4 2 aaaabbaaaa 3 aabbbcccaaddddaaeeeee 5 abcde 1 aaaaabcde Output: 8 12 5 5
Added by: | TouristGuide |
Date: | 2012-08-27 |
Time limit: | 1s-2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
hide comments
|
|||||
2012-09-09 18:19:40 :D
Moved to tutorial. Not only is it very basic, but we already have very similar problems in classical. |
|||||
2012-09-05 21:47:29 007: Name stolen
use stl containers and algos.....hv fn |
|||||
2012-09-03 15:05:11 Arun Lakshman
Again cin and cout costs TLE ...Finally AC :) |
|||||
2012-09-02 23:09:00 Alex Velazquez
"Master Bates".... seriously? |
|||||
2012-09-01 18:13:18 Sardar Khan
a piece of meal :D |
|||||
2012-08-30 17:38:03 BLANKRK
easy one!!! |
|||||
2012-08-30 14:34:23 AC Srinivas
using stl is best. |
|||||
2012-08-30 11:29:26 Chirag
please check my solution....i am getting correct answer for all given testcases my id is 7560456 i am getting wa... edit: got AC Last edit: 2012-09-03 19:47:46 |
|||||
2012-08-30 11:07:33 Naman
Too easy!! |