SCHEDULING TRAINING
A candidate named Alice is onboarding to Intuit Intuit demands a required set of trainings to completed. There are 2 trainings for Alice to complete. Each of these trainings has M courses within them which have to be completed. The courses within a training need to be completed in the order they were created. Each course takes time to complete Once you start the course, either you spend the entire time in completing the course, or you would need to re-take the entire course.
Alice already has some P prior commitments. She wants to complete all the trainings as carly as possible. Help her determine the order in which she can take these trainings Output the minimum number of days required for her to complete all the trainings. Output-1 if it is not possible to complete the trainings with her schedule
Input Format:
The first line has integer M. denoting the total number of courses within both trainings
Next 2 lines each having M space separated integers, stating the time taken for a course within the training.
Next line denotes the number of prior commitment that Alice has, denoted by P
Next P lines contain 2 space separated integers, stating the starting time and ending time of those commitments (24 hr scale)
Sample Input
3
1 2 3
2 1 3
4
11 12
0 8
14 18
16 23
Sample Output:
3