Bowling Strategy :) (Codechef Contest Problem)
Question:-
In a cricket game, an over is a set of six valid deliveries of balls performed by one player ― the bowler for this over.
Consider a cricket game with a series of overs (numbered through ) played by players (numbered through ). Each player may be the bowler for at most overs in total, but the same player may not be the bowler for any two consecutive overs. Assign exactly one bowler to each over in such a way that these rules are satisfied or determine that no such assignment exists.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains three space-separated integers , and
Output
For each test case:
- If there is no valid assignment of bowlers to overs, print a single line containing the integer .
- Otherwise, print a single line containing space-separated integers. For each valid , the -th of these integers should be the number of the player assigned as the bowler for the -th over.
Constraints
Example Input
2
4 3 2
5 4 1
Example Output
1 2 3 2
-1
Explanation
Example case 1: The following is a valid assignment:
- Bowler 1 bowls the -st over.
- Bowler 2 bowls the -nd and -th overs.
- Bowler 3 bowls the -rd over.
It is valid since no bowler bowls more than overs and each two consecutive overs have different bowlers.
Example case 2: There is no valid assignment in which each of players bowls at most over out of 5.
Solution:-
t=int(input())
for i in range(t):
n,k,l=map(int,input().split())
if(n==1):
print("1")
continue
elif(k==1):
print("-1")
continue
elif(n<=k*l):
for j in range(1,n+1):
if(j%k!=0):
print(j%k,end=" ")
else:
print(k,end=" ")
#continue
elif(n>k*l):
print("-1",end="")
print();
Comments
Post a Comment