Musical Bench

 Coding Problem Keys 

 Musical Bench 

 Problem Statement 

A group of P players are playing musical bench game in which B number of benches are present in a circular fashion and are placed with equal gaps between adjacent benches. Before the game starts, each one of the players are sitting on any one of these benches which is their initial position IP and each player is having his/her unique id ID. Music is played M number of times (M denotes the number of Round(s) with the duration of play varying which is denoted by M(i). Each player takes his/her own time T(i) to move from one bench to another. If the music is played, players keep moving form one bench to another. At the end of the round one of the benches is removed from the game and also the players who are sitting on that bench are eliminated from the game. The program must print the players ID whose are remaining in the game along with their bench number B. If all the players are eliminated in the game print -1. It is assured that when the music is stopped, the duration for which the music is played is a common multiple of T(i) of all players.

 Input Format 

First line contains B and P.
Second line contains the players IDs separated by space.
Third line contains T(i) separated by space.
Fourth line contains players initial bench position IP separated by space.
Fifth line contains M (number of rounds or the number of times the music is played).
Sixth line contains M(i) separated by space.
Seventh line contains the bench number which is removed after each round (when the music is stopped). 

 Output Format 

First line contains the list of ids of the players who are not eliminated and their bench number separated by a colon (or contains -1 if all players are eliminated).

 Boundary Conditions 

2 <= B, P <= 100
M <= B

 Example Input/Output 1 

 Input 

10 6
100 200 300 400 500 600
2 3 4 2 5 3
9 8 9 5 2 1
60 120 180 60 60
4 5 3 6 7

 Output 

100:10 200:9 600:1

 Example Input/Output 2 

 Input 

6 4
100 200 300 400
2 4 6 2
2 3 5 1
4
48 36 12 24
1 2 3 5

 Output 

-1

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

b,p=map(int,input().split())
id=list(map(int,input().split()))
playertime=list(map(int,input().split()))
position=list(map(int,input().split()))
round=int(input())
roundtime=list(map(int,input().split()))
benchrem=list(map(int,input().split()))
isbenchremoved=["0"]*101
for i in range(round):
    for j in range(p):
        if isbenchremoved[position[j]]==1:continue
        jump=roundtime[i]//playertime[j]
        pos=position[j]
        while jump>0:
            pos+=1
            if pos==b+1:pos=1
            if isbenchremoved[pos]=="0":jump-=1
        position[j]=pos
    isbenchremoved[benchrem[i]]=1
c=0
for i in range(p):
    if isbenchremoved[position[i]]=="0":print(str(id[i])+":"+str(position[i]),end=" ");c+=1
if c==0:print("-1")
#Published By PKJCODERS

 Programming Language: C Language 

#include<stdio.h>
#include <stdlib.h>
int main(){
    int b,p;
    scanf("%d%d",&b,&p);
    int id[p];
    for(int i=0;i<p;++i)scanf("%d",&id[i]);
    int playersTime[p];
    for(int i=0;i<p;++i)scanf("%d",&playersTime[i]);
    int position[p];
    for(int i=0;i<p;++i)scanf("%d",&position[i]);
    int rounds;
    scanf("%d",&rounds);
    int roundTime[rounds];
    for(int i=0;i<rounds;++i)scanf("%d",&roundTime[i]);
    int benchRem[rounds];
    for(int i=0;i<rounds;++i)scanf("%d",&benchRem[i]);
    int isBenchRemoved[101]={0};
    for(int rnd=0;rnd<rounds;++rnd){
        for(int i=0;i<p;++i){
            if(isBenchRemoved[position[i]])continue;
            int jumps=roundTime[rnd]/playersTime[i];
            int pos=position[i];
            while(jumps>0){
                pos++;
                if(pos==b+1){
                    pos=1;
                }if(!isBenchRemoved[pos])jumps--;
            }position[i]=pos;
        }isBenchRemoved[benchRem[rnd]]=1;
    }
    int counter=0;
    for(int i=0;i<p;++i){
        if(!isBenchRemoved[position[i]]){
            printf("%d:%d ",id[i],position[i]);
            counter=1;
        }
    }if(counter==0)printf("-1");
}
//Published By PKJCODERS

 (Note: Incase If the code Doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Highly Profitable Months

Flowchart Logic 047

Desktop Products

Words Starting with Upper Case

Find Maxima/Minima

Matrix Print Excluding Border Elements