Crunch Time
YOU: "So you were the head chef for this event. Is that the role you wanted?"
PATRICK: "It's not the role I expected, but honestly, I had a great time learning how to cook!"
YOU: "What were you expecting instead?"
PATRICK: "I don't know, figured I'd just be helping out. Kevin sort of threw it at me last minute. Wasn't planning on running the whole kitchen, but it was fine. He had a way of just deciding things for you like that."
YOU: "Did you hear anything unusual that night? Anything from backstage?"
PATRICK: "Nah, it's loud in here. Pots, extractor fans, the works. Zach came by at some point, we talked algorithms for a bit. That's about it. Man, it just sucks to hear about Kevin though. Known him for years. Good guy. Should've gone and said hi to him at some point that night. Didn't get the chance.
Make sure you catch whoever did this."
It's Patrick's responsibility to cook all the food for the ACPC Ball. Unfortunately, Patrick has never cooked a single thing in his life, so he'll need to study hard in order to learn everything in time.
Patrick's cookbook has pages, which he plans to read in order from the first page to the last. He also has
focus values
satisfying
. On his
th consecutive day of reading, Patrick can read at most
pages.
Patrick may rest on any day instead of reading. A single day of rest clears his exhaustion: the next time he reads, it again counts as his first consecutive reading day, allowing up to pages. Because his focus values only extend to
, Patrick cannot read more than
days in a row. After
consecutive reading days, he is too exhausted and must rest before reading again.
To keep himself on track, Patrick has set checkpoints for himself. The
th checkpoint
requires that by the end of day
, Patrick has read at least
pages in total. If Patrick ever fails a checkpoint, he gives up and asks ChatGPT for the recipes instead, which would be catastrophic for the guests.
Determine the minimum number of days required for Patrick to finish the entire cookbook without failing any checkpoint, or output if this is impossible.
Input
The first line contains three integers ,
, and
, the number of pages in Patrick's cookbook, the number of focus values, and the number of checkpoints.
The second line contains integers
(
), indicating that Patrick can read up to
pages on his
th consecutive reading day.
The next lines each contain two integers
and
, indicating that by the end of day
, Patrick must have read at least
pages. Checkpoints are given in strictly increasing order of
.
Output
Output a single integer, the minimum number of days required for Patrick to finish his cookbook without failing any checkpoint, or output if this is impossible.
Example
Input 1
19 3 2
10 5 3
2 12
3 15
Output 1
4
Patrick can read all pages in
days as follows:

Note that Patrick only needs pages on day
but he could have read up to
.
Input 2
19 3 0
10 5 3
Output 2
3
Patrick can read pages, then rest, then read another
pages. This was not possible in the previous case due to Patrick's checkpoints.
Input 3
15 5 5
5 4 3 2 1
1 5
2 9
3 12
4 14
5 15
Output 3
5
To meet his checkpoints, Patrick must read for 5 days in a row without resting.
Input 4
15 5 2
5 4 3 2 1
1 5
2 10
Output 4
-1
The second checkpoint requires pages by day
, but Patrick can read at most
pages in his first two days, so it is impossible for him to pass this checkpoint.
Comments