That Is My Score! Codechef Solution |Problem Code:WATSCORE

That Is My Score! Codechef Solution

Problem

You are participating in a contest which has 1111 problems (numbered 11 through 1111). The first eight problems (i.e. problems 1,2,…,81,2,…,8) are scorable, while the last three problems (99, 1010 and 1111) are non-scorable ― this means that any submissions you make on any of these problems do not affect your total score.

Your total score is the sum of your best scores for all scorable problems. That is, for each scorable problem, you look at the scores of all submissions you made on that problem and take the maximum of these scores (or 00 if you didn’t make any submissions on that problem); the total score is the sum of the maximum scores you took.

You know the results of all submissions you made. Calculate your total score.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains a single integer NN denoting the number of submissions you made.
  • NN lines follow. For each ii (1≤i≤N1≤i≤N), the ii-th of these lines contains two space-separated integers pipi and sisi, denoting that your ii-th submission was on problem pipi and it received a score sisi.

Output

For each test case, print a single line containing one integer ― your total score.

Constraints

  • 1≤T≤101≤T≤10
  • 1≤N≤1,0001≤N≤1,000
  • 1≤pi≤111≤pi≤11 for each valid ii
  • 0≤si≤1000≤si≤100 for each valid ii

Subtasks

Subtask #1 (15 points): all submissions are on the same problem, i.e. p1=p2=…=pNp1=p2=…=pN

Subtask #2 (15 points): there is at most one submission made on each problem, i.e. pi≠pjpi≠pj for each valid i,ji,j (i≠ji≠j)

Subtask #3 (70 points): original constraints

Sample Input 1

Sample Output 1

Explanation

Example case 1: The scorable problems with at least one submission are problems 22 and 88. For problem 22, there are two submissions and the maximum score among them is 4545. For problem 88, there are also two submissions and the maximum score is 9090. Hence, the total score is 45+90=13545+90=135.

Example case 2: No scorable problem is attempted, so the total score is 00.

That Is My Score! – CodeChef Solution in CPP

#include <iostream>
#include <vector>
using namespace std;
int solve_test()
{
    int my_score = 0;
    // Create a vector of 8 element and set all of them to 0
    vector<int>scorable_marks(8, 0);
    int submission_id, submission_score;
    int number_submission;
    cin >> number_submission;
    for(int i =0; i < number_submission; i++)
    {
        cin >> submission_id >> submission_score;
        if(submission_id > 8 && submission_id < 1)
            continue;
        else
        {
            // There is a scorable submission_
            if(scorable_marks[submission_id-1] < submission_score)
                scorable_marks[submission_id-1] = submission_score;
        }
    }
    for(int i=0; i < scorable_marks.size(); i++)
        my_score += scorable_marks[i];
    return my_score;
}
int main() {
	int test_cases;
	cin >> test_cases;
	while(test_cases--)
	    cout << solve_test() <<endl;
	return 0;
}

Disclaimer: The above Problem (That Is My Score!  ) is generated by CodeChef but the solution is provided by  Chase2learn. This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment