# Help me in solving WATSCORE problem

### My code

``````#include <iostream>
using namespace std;

int main() {
int t;
cin >> t;

while(t--){
int n;
cin >> n;

int problem[n];
int score[n];

for(int i =0; i <n; i++){
cin >> problem[i] >> score[i];
}

int totalScore = 0;
int maxScore = 0;

for(int i = 0 ; i <n; i++){
for(int j = i+1; j < n; j++){
if(problem[i] == problem[j] && problem[i] <= 8){
maxScore = max(score[i], score[j]);

totalScore += maxScore;
}
}
}

cout << totalScore << endl;
}
return 0;
}
``````

Problem Link: WATSCORE Problem - CodeChef

@abhi_coder01
U have done some logical mistakes .
I have corrected it in your code. Hope u will get it.

``````#include<bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;

while(t--){
int n;
cin >> n;

int problem[n];
int score[n];

for(int i =0; i <n; i++){
cin >> problem[i] >> score[i];
}

int totalScore = 0;
int maxScore = 0;

for(int i = 0 ; i <n; i++){
maxScore=score[i];
for(int j = i+1; j < n; j++){
if(problem[i] == problem[j] && problem[i] <= 8){
maxScore = max(maxScore, score[j]);
score[j]=0;
}
}
if(problem[i]<=8)
totalScore += maxScore;
}

cout << totalScore << endl;
}
return 0;
}
``````