You are not logged in. Please login at www.codechef.com to post your questions!

×

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);
        }
    }
}

asked 06 Oct '16, 09:49

chandubaba's gravatar image

3★chandubaba ♢
713
accept rate: 0%

edited 06 Oct '16, 12:21

admin's gravatar image

0★admin ♦♦
17.1k347485513

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×12,076
×581
×84
×4
×2

question asked: 06 Oct '16, 09:49

question was seen: 411 times

last updated: 06 Oct '16, 12:21