Help me in solving WATSCORE problem

My issue

my understanding of problem statement or my logic is wrong,
what i tried to do is i tried to create a array (prob) and get the values in 3rd line as index and value and store the value in the array,
i also checked if the stored value is lesser than the current value if its lesser change the value

can some one explain the problem statement or logic please.

My code

#include <stdio.h>

int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	while(t--) {
	    int n = 0;
	    scanf("%d", &n);
	    int prob[11] = {0}, index = 0, value = 0;
        while(n--) {
            scanf("%d %d",&index , &value);
            if(prob[index] <= value) {
                prob[index] = value;
            }
        }
        int totalScore = 0;
        for(int i = 0; i < 8; i++) {
            totalScore += prob[i];
        }
        printf("%d\n", totalScore);	    
	}   
	return 0;
}


Problem Link: WATSCORE Problem - CodeChef

@vikkassolo
The logic is make a freq array of size 12 for all 11 problems now the scorable problems are from 1-8 so take them and pick the maximum score them into your code .
like for
1 50
1 90
2 30
2 50
2 40
9 100;
your score will be 90+50=140
90 for problem 1 which is maximum for 1
and 50 for problem 2 which is maximum for 2
for 9 u got 100 but its not scorable problem.

ohh ok, thanks for your explanation i understood the question but i don’t have any idea about how to implement it :sweat_smile:

i implemented using struct, it was partially correct and subtask 2 passed, 1 and 3 test case didnt pass

type or paste code here
#include <stdio.h>
struct ques {
    int qnos;
    int score;
};
int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	while(t--) {
	    int n;
	    scanf("%d",&n);
	    struct ques q[n];
	    for(int i = 0; i < n; i++) {
	       scanf("%d %d",&q[i].qnos,&q[i].score);
	    }
	    int totalScore = 0;
	    for(int i = 0; i < n; i++) {
	        if (q[i].qnos > 8) {
	            q[i].score = 0;
	        }
	        for(int j = i+1; j < n; j++) {
	            if(q[i].qnos == q[j].qnos && q[i].score > q[j].score) {
	                q[j].score = 0;
	            }
	        }
	        totalScore += q[i].score;
	    }
	    printf("%d\n", totalScore);
	}
	return 0;
}

i solved it one very small mistake i didn’t add else to the if statement that check the score :sweat_smile:

#include <stdio.h>
struct ques {
    int qnos;
    int score;
};
int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	while(t--) {
	    int n;
	    scanf("%d",&n);
	    struct ques q[n];
	    for(int i = 0; i < n; i++) {
	       scanf("%d %d",&q[i].qnos,&q[i].score);
	    }
	    int totalScore = 0;
	    for(int i = 0; i < n; i++) {
	        if (q[i].qnos > 8) {
	            q[i].score = 0;
	        }
	        for(int j = i+1; j < n; j++) {
	            if(q[i].qnos == q[j].qnos) {
    	            if (q[i].score > q[j].score) {
    	                q[j].score = 0;
    	            }
    	            else {
    	                q[i].score = 0;
    	            }
	            }
	        }
	        totalScore += q[i].score;
	    }
	    printf("%d\n", totalScore);
	}
	return 0;
}
1 Like