Ensure that you are logged in and have the required permissions to access the test.

Winning side

3.5

22 votes
Very-Easy
Problem

A random group of students is playing Game of Ultimate Randomness in ~ bits&bytes Carnival ~. In this game each player receives a random number generated by a computer-based algorithm. Numbers are allotted such that only the recipient of the number knows it and later after every participant gets their number they are directed to make groups such that their sum of numbers of their group members is highest. This year, the theme of Carnival is "Battle of Sexes" and hence there will be Boys vs Girls everywhere in the carnival. You are given the numbers allotted and gender of each player. Your job is to find out which group wins and by how much. The game is so random that there is always one winner.

INPUT FORMAT :
First line of input will contain an integer T, denoting the number of testcases.
Each testcase contains two lines;

  • first line consist of integer N, denoting total number of participants and string S consisting of gender of N different participants.
  • second line consists of array of integer A, where Ai = number allotted to Si.

OUTPUT FORMAT :
Your output should contain T lines, printing the gender of winning side and winning margin. .

CONSTRAINTS :
1≤ T ≤103
1≤ N ≤103
1≤ Ai ≤103
Si = { 'g' , 'b' }

Sample Input
2
5 gbgbg
1 2 3 4 5
5 bgbgb
5 4 3 2 1
Sample Output
g 3
b 3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In first testcase,
sum of numbers allotted to 'g' = 1+3+5 = 9
sum of numbers allotted to 'b' = 2+4 = 6
Clearly winner is 'g' and winning margin is 3

In second testcase,
sum of numbers allotted to 'b' = 1+3+5 = 9
sum of numbers allotted to 'g' = 2+4 = 6
Clearly winner is 'b' and winning margin is 3

Editor Image

?