KETFAST editorial

PROBLEM LINK:

Practice
Contest

Author: Chandan Boruah
Tester: Chandan Boruah
Editorialist: Chandan Boruah

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Sorting.

PROBLEM:

Given a word and time needed to type each english alphabet and the count of letters that can be skipped, print how long does it take to print the word. Note that you can skip exact count of letters and not skip all letters that are same and count once. Example, for ‘aaa’ you can skip 1 ‘a’ for 1 letter and not all the 'a’s. (Quotes for clarity).

Advanced EXPLANATION:

Sort the alphabets in descending order by time needed and then skip as many letters as given. Then sum rest of the letters in the word.

EXPLANATION:

Sort the alphabets in descending order by time needed and then skip as many letters as given so that you can skip the letters that time larger times. All you will be left with is the letters that take lesser (or equal time in some cases), then print the sum of those times.

AUTHOR’S AND TESTER’S SOLUTIONS:

using System;
using System.Collections.Generic;
class some
{
	public static void Main()
	{
		int n=Int32.Parse(Console.ReadLine());
		char[]let="abcdefghijklmnopqrstuvwxyz".ToCharArray();
		for(int t=0;t<n;t++)
		{
			int rem=Int32.Parse(Console.ReadLine());
			string[]ss=Console.ReadLine().Split();
			string word=Console.ReadLine();
			int[]c=new int[word.Length];
			for(int i=0;i<c.Length;i++)
			{
				c[i]=Int32.Parse(ss[Array.IndexOf(let,word[i])]);
			}
			Array.Sort(c);
			Array.Reverse(c);
			int sum=0;int ret=0;
			for(int i=0;i<c.Length;i++)
			{
				if(sum>=rem)ret+=c[i];
				sum++;
			}
			Console.WriteLine(ret);
		}
	}
}