Let C = Int 100 Init to All Zeros
Total Page:16
File Type:pdf, Size:1020Kb

Parking
Your task is to calculate parking rates based on the presence of 3 trucks in a parking lot. The number of trucks parked during any given time interval determines the rate per minute charged to each truck. You are given three rates per minute in the input. You are also given the arrival and departure times of each truck as integers beween 1 and 100.
Strategy: map an array C to the number of trucks in each lot during each time interval. let C = int[100] // init to all zeros read rate[1],rate[2],rate[3] for truck = 1 to 3 read s,e for k = s+1 to e // C[2] counts trucks between t[1] and t[2] C[k]++
Next, iterate through the C array and calculate cost equals number of trucks parked during each minute
( Cj )multiplied by the rate per minute for each truck. cost = 0 // assert: C[j] <= 3 for j = 1 to 100 cost += rate[ C[j] ] * C[j]