#P6759. [USACO06OPEN] 县集市 The County Fair
[USACO06OPEN] 县集市 The County Fair
Problem Description
Every year, FJ likes to go to the county fair. There are booths at the fair, and each booth will give out an exquisite gift at a specific time on that day. FJ has heard about this and hopes to collect as many gifts as possible to share with his cows. To get the gift from booth , FJ must make sure he is at booth exactly at time .
To collect as many gifts as possible, FJ did a detailed investigation. From this investigation, FJ determined the time it takes to travel from booth to booth . The layout of the fair is very unusual, which means that if FJ chooses to detour via other booths while traveling from to , it might take less time than going directly from to . However, the straightforward FJ never does this: if he wants to go from booth to booth , he will definitely spend time to walk from to . In addition, because the fairground is rugged, may be different from .
FJ is at booth at time . Please compute the maximum number of gifts he can collect.
Input Format
Line : An integer , the number of booths.
Lines to : integers. The integer on line is , the time when booth gives out its gift.
Lines to : lines. The first lines describe the time needed for FJ to walk from booth to booths to (). The next lines describe the time needed for FJ to walk from booth to booths to (), and so on. The last lines describe the time needed for FJ to walk from booth to booths to (). For any booth , .
Output Format
One line: An integer, the maximum number of gifts FJ can collect.
4
13
9
19
3
0
10
20
3
4
0
11
2
1
15
0
12
5
5
13
0
3
Hint
Sample Explanation
In the sample, there are booths at the fair. Booth gives out gifts at time , booth at time , booth at time , and booth at time .
FJ first walks from booth to booth , which takes time units, and arrives at time , so he can get the gift. Then he walks from booth to booth , which takes time units, and arrives at time . After waiting for time unit, he can get the gift from booth . Next he walks from booth to booth , which takes time units, and arrives at time , so he can collect the third gift.
Constraints
For of the testdata, , , .
The testdata is from darkbzoj.
Translated by ChatGPT 5