Problem link–>https://www.codechef.com/problems/KETFAST
My Solution–>
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class ketfast
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0)
{
int ans=0;
int skip=sc.nextInt();
int cnt[]=new int[26];
int hash[]=new int[26];
TreeMap<Integer,Integer> vk=new TreeMap();
String alpha="abcdefghijklmnopqrstuvwxyz";
for(int i=0;i<26;i++)
{
cnt[i]=sc.nextInt();
}
String type=sc.next();
for(int i=0;i<type.length();i++)
{
hash[alpha.indexOf(type.charAt(i))]++;
}
for(int i=0;i<type.length();i++)
{
vk.put(cnt[alpha.indexOf(type.charAt(i))],hash[alpha.indexOf(type.charAt(i))]);
}
int last=vk.size();
int count=0;
while(skip!=count)
{
if(Integer.parseInt(vk.values().toArray()[last-1].toString())-1>=0)
{
vk.replace(Integer.parseInt(vk.keySet().toArray() [last1].toString()),Integer.parseInt(vk.values().toArray()[last-1].toString())-1);
count++;
}
else
last--;
}
for(Map.Entry m:vk.entrySet())
ans=ans+(Integer.parseInt(m.getKey().toString())*Integer.parseInt(m.getValue().toString()));
System.out.println(ans);
t--;}
}
}
What is Wrong in this approach?