Busy Airport

3.5

6 votes
C++, Sorting, Advanced Sorting, Algorithms
Problem

Checkout at an airport consists of two sequential events first passport check which takes time A minutes and there are B counters present for it. Second is luggage check which takes C minutes and there are D counters present for it.

Functioning of different counters is independent of each other and every passengers must go through both events in order i.e. first passport then luggage check.

Given N passengers and their arrival time A[i]. Find the minimum time in which all the passengers will get their both events done.

Input format

  • First line contains 4 space separated integers denoting A B C D
  • Next line contains N, denoting number of passengers
  • Next line contains N space separated integers, denoting arrival times of passengers (in sorted order)

Output format

Print a single integer denoting the minimum time required to get all passengers done with both events.

Constraints

1A,C1091N,B,D1051A[i]109A[i1]A[i]

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • At end of T=8 min, last passenger has completed first event.
  • At end of T=9 min, last passenger has completed second event. (By this time all passengers have completed both events)
Editor Image

?