Getting WA even when output is correct

November Long Challange 2020 Ada and Dishes
**Logic - **
First I sorted the array C
a= C[n-1]
Start traversing the array from last second elemet and increase time by minimum of “a and C[i]”
and update “a=abs(C[i]-a)”

Please go through my code and help

Are you so sure of your solution as to write that title?

Please include a link to your code so others can try to help you

Thanks for reply
Ya I think my code is correct.
Please tell me the error here is the link
https://www.codechef.com/viewsolution/39600021

Input this
1
2
2 2

your output is 1

for _ in range(int(input())):
    n = int(input())
    c = map(int, raw_input().split())
    print ((n+1)/2)*c[0]

This is the correct approach bro :stuck_out_tongue: (for 1st subtask)
and full soln

for _ in range(input()):
    n = input()
    c = map(int, raw_input().split(" "))
    s = sum(c)
    ans = s
    for x in c: 
        ans = min(ans, max(x, s-x))
    for i in range(n):
        for j in range(i+1,n):
            x = c[i] + c[j]
            ans = min(ans, max(x, s-x))
    print ans

No its 2 for your input

The problem had 12222 accepted solutions. Even if there’s a remote chance that your “correct” output is giving WA it seems very unlikely. I suggest you to edit the title of the post

Even I can see the solutions there, but I want to know the problem in my code, could you help

Try input
1
1
2
your code output is 0

What should I make the title

Thanks for this suggestion, I resolved this
https://www.codechef.com/viewsolution/39665495

But still WA

Try this testcase
1
4
2 2 2 5
for this ans should be 6
you may be getting 7
check your output you might be missing this corner case

Thanks for the suggestion, I have resolved such cases now, but still WA
Here is the link
https://www.codechef.com/viewsolution/39666296

your logic is not correct, every case with n=2 you are returning the minimum but the answer is the maximum; when n= 3 and c=[1,2,5] the answer should be 5 and your code gives WA.

Regarding the title, as you can see, it’s a false asseveration.

No its giving 5 for n=3 and c=[1,2,5] which is correct.
and when n=2 it will not go inside the loop, it just return the max of two.

it was like I said in your original code; for the last one you send here are some wrong answers for n=4 and diferent C[i] values

1 3 5 5 -> yours=9 correct=8
1 4 5 5 -> yours=10 correct=9
2 2 4 4 -> yours=8 correct=6
2 4 5 5 -> yours=11 correct=9
3 4 4 4 -> yours=11 correct=8
3 3 3 3 -> yours=9 correct=6
3 3 4 4 -> yours=10 correct=7
1 2 5 5 -> yours=8 correct=7
1 1 4 4 -> yours=6 correct=5

2 Likes