ADADISH - Editorial

I was also doing the same mistake. Try your code for TC: 2 2 2 5
It will give 7 as the answer but the correct answer is 6.
Intead use this code for n=4
ans = min(max((v[0] + v[3]), (v[1] + v[2])), max(v[3], v[0]+v[1]+v[2]));

1 Like

I was also doing the same mistake. Try your code for TC: 2 2 2 5
It will give 7 as the answer but the correct answer is 6.
Instead use this code for n=4
ans = min(max((v[0] + v[3]), (v[1] + v[2])), max(v[3], v[0]+v[1]+v[2]));

1 Like
if (checkSame(timings)) {
                    timeToReady = (numberOfDishes % 2 == 0) ? timings[0] * (numberOfDishes / 2)
                            : (timings[0] * (numberOfDishes / 2)) + timings[0];
                } else {
                    timeToReady = (totalTime % 2 == 0) ? totalTime / 2 : (totalTime / 2) + 1;
                }
                System.out.println(timeToReady);

this returns the actual correct answer. but still show WA . someone please explain why? or official answer is wrong?

here is my solution CodeChef: Practical coding for everyone

thanks player007,you are right, i got my mistake.
The above code will fail for 5222 test case

@player007 thankyou , it worked .

Is something wrong with the interface. I am getting SIGSTP errors on my code. I tried copy-pasting a code which was successfully submitted. It still throws the same error.

can somebody help me with EOF error in Python ā€¦ i dont know why in every question i am getting error. I have choosen python 3.6

I have a different approach for this problem.
Approach of SUBSEQUENCES.
Suppose we have dishes time as 1,2,3,4. Total time sum is 8. And Solution for every problem will be T/2+something. For this we find sum of different subsequences and find sum which is minimum but is greater than 4 or equal to 4. Here 1,3 subsequence sum is 4 So answer is 4.
Same for exp 2,2,2 . In this nearest subsequence sum to 3 is 4. So Answer is 4.
Solution got accepted. Hope u like this approach.

SUBSEQUENCES help us to get all possible combination of dishes and then we can simply compare.

The output for 2 3 4 5 is 9, not 7.

1 Like

Exactly !!!

doing this shows NZEC error :
int t = input.nextInt();
input being an object of scanner class.
Could someone explain to me why am I getting this error and how can I remove it

Your algo will not work in case of
5 4 3 3 3
This question should be solved using recursion not by greedy.

> #include <bits/stdc++.h>
> using namespace std;
> bool solve(long long arr[],long long n)
> {
>   long long first = arr[0];
>  
>   for (long long i = 1; i < n; i++)
>     if (arr[i] != first)
>       return 0;
>   return 1;
> }
> int main()
> {
>     ios_base::sync_with_stdio(false);
>     cin.tie(NULL);
>     long long t;
>     cin>>t;
>     while(t--)
>     {
>         long long n;
>         cin>>n;
>         long long a[n];
>         for(long long i=0;i<n;i++)
>         cin>>a[i];
>         sort(a,a+n);
>         if(solve(a,n))
>         {
>             long long d=n/2;
>             long long r=n%2;
>             cout<<((d*a[0])+(r*a[0]))<<endl;
>         }
>         else{
>         long long x,y,cnt=0;
>         int z=1;
>         sort(a,a+n);
>         x=a[n-2];
>         y=a[n-1];
>         long long i=n-2;
>         while(x>=0&&y>=0&&i>=0)
>         {
>             if(x<y)
>             {
>                 cnt=cnt+x;
>                 y=y-x;
>                 if(i==0)
>                 {
>                     z=1;
>                     break;
>                 }
>                 else{
>                 x=a[i-1];
>                 i--;
>                 }
>             }
>             else if(x>y)
>             {
>                 cnt=cnt+y;
>                 x=x-y;
>                 if(i==0)
>                 {
>                     z=2;
>                     break;
>                 }
>                 
>                 else{
>                 y=a[i-1];
>                 i--;
>                 }
>             }
>             else
>             {
>                 cnt=cnt+x;
>                 if(i==0)
>                 {
>                     z=3;
>                     break;
>                 }
>                 else{
>                 x=a[i-2];
>                 y=a[i-1];
>                 i--;
>                 }
>                 
>             }
>         }
>         if(z==1)
>         cnt=cnt+y;
>         else if(z==2)
>         cnt=cnt+x;
>         else
>         cnt=cnt+0;
>         cout<<cnt<<endl;
>         }
>     }
>     return 0;
> }

Blockquote

Can anyone tell me where I am wrong,if you can suggest me any failing test case.

why this is not giving AC
https://www.codechef.com/viewsolution/77085695

int n;
cin>>n;

vector a(n);
for(int i=0; i<n; i++)cin>>a[i];

sort(a.begin(),a.end());

if(n==1)cout<<a[0]<<ā€œ\nā€;
else if(n==2)cout<<a[1]<<ā€œ\nā€;
else if(n==3)cout<<max(a[0]+a[1],a[2])<<ā€œ\nā€;
else cout<<min(max(a[0]+a[3],a[1]+a[2]),max(a[0]+a[1]+a[2],a[3]));