BOWLERS - Editorial

Can someone check my request above

I am totally upset with this…
Just forgot this simple test case if k == 1 and n != 1, then return -1;
Because of this i coudn’t submit :disappointed_relieved:

Wrong on testcase
1
15 5 3
Your way of assignment gives consecutive pair of numbers alternatively to avoid repitition of same bowler, on above testcase it will result in an assignment:
1 2 1 2 1 2 3 4 3 4 3 4 till 12 overs and afterwards will be forced to give the last 3 overs to 5th bowler again and again since there is no 6th bowler to complete the pair and avoid repitition. Hence approach is wrong…

Hope it helps :upside_down_face: :slightly_smiling_face:

1 Like

can anyone tell me why i’m getting runtime error in this code:-
#include<bits/stdc++.h>
using namespace std;

#define in unsigned long long int

int main(){
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
// freopen(“output.txt”, “w”, stdout);
#endif
in T;
cin>>T;
while(T–){
in n,k,l;
cin>>n>>k>>l;
if(kl < n ||(l == 1 && n != 1)) cout<<“-1”<<endl;
else{
if(n == 0){cout<<endl; continue;}
in loop = (k
l)/n;
in rmd = n-(loop*k);
for(in i=0;i<10;i++){
for(in j=1;j<=5;j++){
cout<<j<<" “;
}
}
in player = 1;
while(rmd–){
cout<<player<<” ";
player++;
}
cout<<endl;
}
}

return 0;

}

I do a little debugging and i get to know that because of multiply sign in these two lines i’m getting runtime error:-
in loop = (kl)/n;
in rmd = n-(loop
k);

so please anyone tell me what’s wrong with these two lines plz??
here’s my submission:- CodeChef: Practical coding for everyone

same bowler is doing consecutive overs which is wrong

That’s what i said :confused:

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

can anyone tell me reason of getting error.

if(i == K) rep = 0; resets rep only once

Ah, stupid mistake!
Thanks

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTRUN ios_base::sync_with_stdio(NULL); cin.tie(NULL);
int main()
{int t;
cin>>t;
while(t–)
{ FASTRUN ;
int n,k,l;
cin>>n>>k>>l;
if(k*l<n)
cout<<"-1";
else
{
if(k==1&&n>1)
cout<<"-1 “;
else
{int p=0;
for(int i=0;i<n;i++)
{if(p==k)
p=0;
cout<<++p<<” ";}

    }
}
cout<<"\n";
}

}

what’s the error
???

Can anyone please help me with which case I am missing and with what are the incorrections ?? I have tried to solve it with a very simple approach.

#include

using namespace std;

int main()

{

int t;

cin>>t;

for(int i=1;i<=t;i++)

{

    int n,k,l;

    cin>>n>>k>>l;

    if(k*l >= n)

    {

        if(k<n)

        {

            int n1=n/k;

            int r=n%k;

            for(int k1=1;k1<=n1;k1++)

            {

                 for(int j=1;j<=k;j++)

            {

                cout<<j<<" ";

            }

            }

            for(int j=1;j<=r;j++)

            {

                cout<<j<<" ";

            }

            cout<<endl;

        }

        else

        {

            for(int j=1;j<=n;j++)

            {

                cout<<j<<" ";

            }

            cout<<endl;

        }

    }

    else

    {

        cout<<-1<<endl;

    }

}

return 0;

}

#include <bits/stdc++.h>
using namespace std;

int main() {
int t , n , k , l ;
cin>>t ;
for(int i=0 ; i<t ; i++){
cin>>n >>k >>l ;
int check=1;
if(k==1 && n!=1){
cout<<"-1"<<endl;
}
else if(l==1){
if(k<n){
check=0;
}
else{
if(k==n){
for(int j=1 ;j<=k ; j++){
cout<<j<<" “;
}
cout<<endl;
}
else if(k>n){
for(int j=1 ; j<=n ; j++){
cout<<j<<” “;
}
cout<<endl;
}
}
}
else{
if(k<=n){
if(k==n){
for(int j=1 ; j<=k ; j++){
cout<<j<<” ";
}
cout<<endl;
}
else{
int remaining = n-k;
l=l-1;
if(l*k >= remaining){
for(int j=1 ; j<=k ; j++){

                        cout<<j<<" ";
                    }
                
                    // int end;
                    int c=0;
                    int end= ceil((double)remaining/l);
                    for(int j=0 ; j<l ; j++){
                        for(int k=1 ; k<=end; k++){
                            if(c<n-k){
                                cout<<k<<" ";
                                c=c+1;
                            }
                            else{
                                break;
                            }
                        }
                    }
                    cout<<endl;
                    
                }
                else{
                    check=0;
                }
                
            }
            
        }
        else{
            for(int j=1 ; j<=n ; j++){
                cout<<j<<" ";
            }
            cout<<endl;
            
        }
    }
    if(check==0){
        cout<<"-1"<<endl;
    }
    
    
}
return 0;

}

plz tell where my code might be failing .