Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Code Written by : John Nixon
- #Date: 15:10:2022 Time: 14:24:18
- #Copyrights are applicable
- import sys
- import os
- from collections import defaultdict
- sys.setrecursionlimit(10000)
- try:
- sys.stdin = open('./input.txt', 'r')
- sys.stdout = open('./output.txt', 'w')
- except:
- pass
- for _ in range(int(input())):
- n = int(input())
- freq = defaultdict(list)
- if n == 0:
- print(0)
- continue
- str = input()
- costs = list(map(int,input().split()))
- for char,cost in zip(str,costs):
- freq[char].append(cost)
- ans = 0
- for char in freq:
- freq[char].sort()
- freq[char].pop(-1)
- # print(freq[char])[::-1]
- ans += sum(freq[char])
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement