Quick actions

cmd+k|ctrl+k

Navigation

Languages

Test3

Snippet info

Language

Python

Visibility

public

Author

dokel

Created

2018-11-06T16:58:08Z

Updated

2018-11-06T18:26:02Z

if __name__ == "__main__":
    str_in = list(map(int, input().split()))
    lifts_count = str_in[0]
    groups_count = str_in[1]
    lift_size = str_in[2]
    lift_time = str_in[3]

    people_arrived = [0]*50;
    arrivals = [list()]*groups_count
    for i in range(0, groups_count):
        group = list(map(int, input().split()))
        group_arrive = group[0] #less or equal to 50
        group_size = group[1]
        
        people_arrived[group_arrive] = group_size
        arrivals[i] = group
    for i in range(1, 50):
        people_arrived[i] = people_arrived[i-1] + people_arrived[i]
    total_people = people_arrived[49]

    ## Tuples (Time of waiting, Amount of people)
    waiters = list()

    people_transported = 0
    current_arrival = 0 ##Number of group, man from which is first in queue
    next_transport = [0]*lifts_count
    available_lift = 0
    while people_transported < total_people:
        sec = next_transport[available_lift]
        
        people_waiting = people_arrived[min([sec, 49])] - people_transported
        if people_waiting <= 0:
            sec = arrivals[current_arrival][0]
            people_waiting = people_arrived[sec] - people_transported
        
        ##Here we know for sure, that there is free lift, and there is people
        ##in queue
        
        people_sent_now = min(lift_size, people_waiting)
        people_transported = people_transported + people_sent_now
        print('lift', available_lift, 'will run at sec', sec, 'with',people_sent_now, 'people')
        while current_arrival < groups_count and arrivals[current_arrival][1] <= people_sent_now:
            waiters.append((arrivals[current_arrival][1], sec-arrivals[current_arrival][0]))
            people_sent_now = people_sent_now - arrivals[current_arrival][1]
            current_arrival = current_arrival+1
        if(current_arrival < groups_count):
            waiters.append((people_sent_now, sec-arrivals[current_arrival][0]))
            arrivals[current_arrival][1] = arrivals[current_arrival][1] - people_sent_now
            
        ##Updating info about lifts
        next_transport[available_lift] = sec + lift_time*2
        available_lift = (available_lift+1)%lifts_count
    
    
    #print(waiters)            
    time_waiting = 0
    for i in range(0, len(waiters)):
        time_waiting = time_waiting + waiters[i][0]*waiters[i][1]
    print(lift_time + time_waiting/total_people)
INFO