# WCC - Editorial

Tester: Manan Grover, Tejas Pandey
Editorialist: Kanhaiya Mohan

Cakewalk

None

# PROBLEM:

In a Chess match, The winner of a game gets 2 points, and the loser gets 0 points. If it’s a draw, both players get 1 point each.

The total prize pool of a Chess championship is 100 \cdot X. At the end of 14 classical games, if one player has strictly more points than the other, he is declared the champion and gets 60 \cdot X, and the loser gets 40 \cdot X.

If the total points are tied, then the defending champion Carlsen is declared the winner. However, if this happens, the winner gets only 55 \cdot X, and the loser gets 45 \cdot X.

Given the results of all the 14 games, output the prize money that Carlsen receives.

The results are given as a string of length 14 consisting of the characters C, N, and D.

• C denotes a victory by Carlsen.
• N denotes a victory by Chef.
• D denotes a draw.

# EXPLANATION:

Observation

Note that if a player wins more matches, he would definitely gain points. Similarly, if both players win the same number of matches, they have the same number of points.

This means that we can calculate the prize money just by comparing the number of wins of both players. The points gained per win do not affect the result.

In this problem, we just need to implement the problem statement. The focus is on our ability to translate the problem statement into functioning error-free code.

Let X denote the number of wins by Carlsen and Y denote the number of wins by Chef. We can calculate these values by a single traversal of the string.

• If X > Y: The number of matches won by Carlsen is strictly greater than that of Chef. Thus he gets 60 \cdot X.
• If X = Y: The total points are tied. Defending champion Carlsen wins 55 \cdot X.
• If X <Y: Carlsen loses and gets 40 \cdot X.

# TIME COMPLEXITY:

The time complexity is O(|S|) as we need to traverse the whole string to calculate the number of wins. Here, since |S| = 14, which is very small, the time complexity is O(1) per test case.

# SOLUTION:

Editorialist's Solution
#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
int X;
cin>>X;

string S;
cin>>S;

int carlsen = 0;
int chef = 0;
for(int i = 0; i<14; i++){
if(S[i] == 'C')
carlsen++;
else if(S[i] =='N')
chef++;
}

if(carlsen > chef){
cout<<60*X;
}
else if(carlsen == chef){
cout<<55*X;
}
else{
cout<<40*X;
}
cout<<endl;
}
return 0;
}