Find the maximal value of the profit for playing a single-player game described in the problem statement
How to get 20 points
Let’s generate all permutations of the order of the questions and calculate the score for each of them. Among the scores for all the orders, choose the maximal. Then just output the maximal obtained score. Since there are exactly N! permutations of the set of N questions and a check of a single order takes O(N) time, the complexity of such a solution is O(N!*N).
In C++ you can use STL routine next_permutation for simple generation of all the permutations.
This solution solves the first subtask, however, it is too slow to get the full points.
How to get 100 points
Let us calculate K - the number of the questions that would be answered correctly by Chef. Clearly, the ith question will be answered correctly if the ith sumbol in the first string equals to the ith symbol in the second string.
If K = N, there is no other option than Chef answers all the questions correctly and gets WN dollars of profit.
Otherwise, using any question than can be answered incorrectly, we can obtain any number of correct answers between 0 and K inclusively. Then the answer is, therefore, the maximal value of Wi for 0 ≤ i ≤ K.
The complexity of such a solution is O(N) for a single test case.
@prasadram126 Please change long int to long long int and then try again. The constraints of the problem are such that they need a datatype as large as long long int.
This is the link to your updated solution. https://www.codechef.com/viewsolution/8535868
@anuragkumar33 I think you need to make arrays A and B a little bit bigger (say, 1010), because string of length N needs N + 1 byte of memory (string itself plus ‘\0’).
If cnt = n, Chef answers all questions correctly and there is no other option than Chef gets W_n dollars of profit, because he can’t leave the game when he wants. For example, for test
@raunak_parijat thanks for you help , i have one question, in the problem page value of wi at max 10^9 i have tested my code with 10^9 it’s working fine .So can you please give me any test case where it’s giving WA?