Thursday, October 19, 2017

Jersey Number - Highest in Team

In a school there are N students standing in a straight line. Their Jersey numbers from left to right are passed as the input. The students are to be divided into teams of size T starting from left. First T students form Team 1, next T students form Team 2 and so on. If N is not divisible by T and say the remainder is R, the R students are distributed among the teams formed so far in a round robin fashion (starting from the first team) until the R students are assigned to one of the teams. Once the teams are formed, the program must print the highest jersey number in each team.

Input Format:
The first line contains N. The second line contains the jersey numbers of N students separated by a space. The third line contains T.

Output Format:
The highest jersey number in each team separated by a space.

Boundary Conditions: 1 <= N <= 9999999

Example Input/Output:
Input:
10
1 5 8 2 4 11 3 6 9 7
4
Output:
9 11

Solution:
n=int(input())
jersey=[int(x) for x in input().split()]
t=int(input())
teamc=n//t
if teamc==0:
    teamc=1
maxlist=[]
for i in range(teamc):
    maxlist.append(max(jersey[i*t:i*t+t]))
ctr=0
for i in range(t*teamc,n):
    maxlist[ctr]=max(maxlist[ctr],jersey[i])
    ctr+=1
    if ctr==len(maxlist):
        ctr=0
print(*maxlist)
Share: