WDTBAM - Editorial

Problem Link

Practice

Contest

Difficulty

CakeWalk

Pre-requisites

Basic programming language constructions

Problem

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.

Setter’s Solution:

Can be found here

Tester’s Solution:

Can be found here

Whats wrong with this code?

I too did the same thing here. But why still my code got WA? CodeChef: Practical coding for everyone

can any body please tell me where my solution is failing

please check what’s wrong with this code my code

can any one tell what’s wrong with this code

https://www.codechef.com/viewsolution/8437975

can any one tell what’s wrong with this code?

https://www.codechef.com/viewsolution/8540459

check this video editorial

3 Likes

Can anybody tell why my program has not given complete 100 points. where my program lacks.
https://www.codechef.com/viewsolution/8450527

Can anyone tell me whats wrong in my code?
CodeChef: Practical coding for everyone

@amitking you get WA because of no newline character at end of each testcase output check this CodeChef: Practical coding for everyone

What is the problem with this solution: CodeChef: Practical coding for everyone

I tried running it this way: java Codechef< input.txt > output.txt

and had the test case input in input.txt and it runs fine.

Hi every one cay any one please tell me whats wrong with this solution? After verifying with setter’s solutions i modified my solution which is giving AC ,i got shocked because both solutions are same in perceptive of algorithms .The difference between two solutions are in the first one using one for loop i am checking no.of correct answers and taking input of w’s , in the second solution i have separated the above logic into two different for loops , both are doing the same thing then why i got WA for first solution can one please tell me either reason or any test case where it’s failling?

Hi every one cay any one please tell me whats wrong with this solution? After verifying with setter’s solutions i modified my solution which is giving AC ,i got shocked because both solutions are same in perceptive of algorithms .The difference between two solutions are in the first one using one for loop i am checking no.of correct answers and taking input of w’s , in the second solution i have separated the above logic into two different for loops , both are doing the same thing then why i got WA for first solution can one please tell me either reason or any test case where it’s failling?

Can someone enlighten me as to why my code is not working?

I keep on getting WA and SIGSEGV on this code. Can anyone please point out what I’m doing wrong?

this code

WA and I don’t know why!!
https://www.codechef.com/viewsolution/9015414
Anybody Help

I am a bit new here and a little help would be greatly appreciated. I tried the below code on Turbo C++, and it worked but here it says wrong answer. Any ideas why that may be?

https://www.codechef.com/viewsolution/9246713

like everyone else: I can’t get this to work on the submission. It works on the sample data and I’ve compared to some of the completed solutions and it looks equivalent to me but I still get a WA.

https://www.codechef.com/viewsolution/9281660

T=int(input())
for t in range(0,T):
N=int(input())
ca=input()
ga=input()
count=0
winnings=[]
win=list(map(int,input().split()))
for i in range(0,len(ca)):
if ca[i]==ga[i]:
count=count+1
if count==0:
print(win[0])
else:
for i in range(1,count+1):
winnings.append(win[i])
print(max(winnings))