UWCOI21C - Organisation - Editorial

Yes
It’s not setters mistake. It was clearly mentioned that “there can be a color with 0 ducks” and “sum of ducks is n*k”
Does this not clarify the constraint ?

Yes from here one can infer like for each duck the number can go upto nk. Sorry its my mistake But it can like be mentioned in the question
0<= m <= n
k for better clarity

1 Like

this editorial code is not working for this test case how
1
5 4
12 8 0 0 0 0

Just check please

Can anyone explain why the solution to subtask 3 will always work? Any proof would be helpful

Setter’s solution is giving WA. Why?
He missed taking t test cases.

Think in term of averages. If there is value <k then we can be sure there will be value >k and vice versa.

now I will cry if I see this mistake again I also used int instead of long long and that costed me the whole time.

This is exact same as setters code and he has used #define int long long.

sorry did not see it

Editorialist forgot to input number of testcases, hence WA

Actually, he forgot to input the test cases t. That’s why it’s getting WA.

1 Like

Can someone please help with this code. It’s giving error for all subtasks. A testcase would really be helpful

        ll T=1;
        prag;
        cin>>T;
        while(T--)
        {
         
        ll n,K,p;
        cin>>n>>K;
        pair<ll,ll> col[n+1];
        forz(i,n+1)
        {
            cin>>p;
            col[i].F=p;
            col[i].S=i;
        } 

        sort(col,col+n+1);
        // forz(i,n+1)
        // {
            
        //     cout<<col[i].F<<" "<<col[i].S<<endl;
           
        // // } 


        ll ptr=n;
        forz(i,n)
        {
            if(ptr==-1)
            {
                cout<<0<<" "<<0<<" "<<0<<" "<<1<<endl;
            }
            else
            {
                
                if(col[ptr].F>=K)
                {
                cout<<K<<" "<<col[ptr].S<<" "<<0<<" "<<0<<endl;
                col[ptr].F-=K;
                }
                else if(col[ptr].F<K)
                {
                        if(ptr>0)
                        { 

                                ll rem=K-col[ptr].F;
                                ll c1=col[ptr].F,m1=col[ptr].S;
                                ptr--;

                                while(col[ptr].F<rem && ptr>=0)
                                ptr--;
                
                                if(ptr==-1)
                                {   
                                    ll m2;
                                    forz(i,n+1)
                                    {
                                    if(i!=m1)
                                    {
                                    m2=i; break;
                                    }
                                    }

                                    cout<<c1<<" "<<m1<<" "<<0<<" "<<m2<<endl;
                                }
                                else
                                {
                    
                                cout<<c1<<" "<<m1<<" "<<rem<<" "<<col[ptr].S<<endl;
                                col[ptr].F-=rem;

                                }
               
                        }
                        else 
                        {
                    
                            ll c1=col[ptr].F,m1=col[ptr].S;
                            ll m2;
                            forz(i,n+1)
                            {
                                if(i!=m1)
                                {
                                m2=i; break;
                                }
                            }
                            cout<<c1<<" "<<m1<<" "<<0<<" "<<m2<<endl;

                        }
            }

            if(col[ptr].F==0) ptr--;

            }

        }

Editorialist forgot to take input of number of testcases.

You can edit and link to your submission. Your code is messed up.

He gave old code by mistake . I will update it.
There were no test cases before.

1 Like

Hey can you see now if its readable :sweat_smile:

First you’re messing with order of output (c and m). Fixing that passes first subatsk.

CodeChef: Practical coding for everyone

can someone please check my code why getting WA in substask 3

1
5 6
0 0 4 6 9 11

It fails on this test case.

Your output-

0 0 5 6
1 0 5 5
2 4 4 2
3 6 4 0
3 0 4 6

@akshitm16 bro,Thanks :innocent: for pointing out the error but what about the other subtasks. I mean is there something wrong with the logic. Did you find some testcase!