Your solution must accept multiple input data sets. Each set will begin with an integer, p (0<= p <=8), specifying the number of programmes to be ordered. When a data set beginning with 0 is encountered, your solution should terminate. Following p on the same line will be p integers specifying the lengths of the programmes in minutes. There is no significance to the order in which these are given.
The next line of input specifies the alignment points. The total number of such points, a (0<= a <=8), appears first followed by a pairs of integers. The first integer in each pair, i (1<= i <=5), gives the importance of the alignment point. Alignment points marked 1 are most important; those marked 2 are of secondary importance, etc. The second integer in each pair, t, specifies the time when the alignment point occurs. No two alignment points in the same data set will have the same value of t.