#P15948. [JOI Final 2026] 面包师 / Baker
[JOI Final 2026] 面包师 / Baker
Problem Description
JOI Bakery is a bakery famous for its mouth-watering croissants. JOI Bakery has bakers numbered from to . Baker () takes minutes to make one croissant. One baker cannot make multiple croissants at the same time.
Today, customers numbered from to are scheduled to visit JOI Bakery, and each customer plans to order one croissant. Customer () will order a croissant at time , where time denotes the time minutes from now. However, a customer who cannot receive their croissant within minutes of ordering will give up and leave the shop. In other words, to fulfill the order of customer (), the croissant must be finished by time (including exactly at time ).
Manager , who manages JOI Bakery, plans to have exactly one baker work today and is considering which baker to send and at what time. Since bakers focus intensely on bread-making during their shift, they ignore all orders placed after their start time (not including exactly at the start time). That is, a baker starting work at time cannot fulfill orders from customers () such that .
Manager is currently considering work plans. The -th plan () is to have baker start work at time . To help with the decision, for each of the plans, he wants to know the maximum number of customers whose orders can be fulfilled if that plan is executed. Note that the time it takes for a baker to start making a croissant after arriving, and the time it takes to start making a new croissant after finishing one, can be ignored.
Given information about the customers visiting JOI Bakery and the work plans, create a program to find the maximum number of customers whose orders can be fulfilled for each plan.
Input Format
Read the following data from the standard input.
Output Format
Write lines to the standard output. The -th line () of the output should contain an integer representing the maximum number of customers whose orders can be fulfilled in the -th work plan.
4 4 6 4
0 2 3 8
2 3
1 6
3 3
4 7
3
2
2
0
20 5 12 4
1 2 4 8 10
1 12
3 10
3 11
15 10
5
4
3
0
100000 6 272273 10
5 9 209 8128 17202 50102
164 9
11 24
835 9267
2 256
2 314156
18475 142
1826 18978
44757 1
4 1646
218 44
2
2
4
3
1
2
5
0
3
2
Hint
Sample 1
Regarding the st work plan, baker starting at time can fulfill the orders of customers , and , for example, as follows:
- First, to fulfill customer ’s order, start making a croissant at time and finish it minutes later at time . (This satisfies the condition to finish by time .)
- Next, to fulfill customer ’s order, start making a croissant at time and finish it minutes later at time . (This satisfies the condition to finish by time .)
- Finally, to fulfill customer ’s order, start making a croissant at time and finish it minutes later at time . (This satisfies the condition to finish by time .)
Customer ’s order is ignored because it arrives after the baker’s start time, so it cannot be fulfilled. Thus, a maximum of customers’ orders can be fulfilled, so the st line outputs .
Regarding the nd work plan, baker starting at time can fulfill the orders of customers and , for example, as follows:
- First, to fulfill customer ’s order, start making a croissant at time and finish it minute later at time . (This satisfies the condition to finish by time .)
- Next, to fulfill customer ’s order, start making a croissant at time and finish it minute later at time . (This satisfies the condition to finish by time .)
Customer ’s order is ignored because it arrives after the start time. Also, the order of customer , which needs to be finished by time , cannot be fulfilled. Thus, a maximum of customers’ orders can be fulfilled, so the nd line outputs .
Regarding the rd work plan, baker starting at time can fulfill orders for customers and , or customers and , but cannot fulfill all orders for customers , and . They also cannot fulfill the order for customer which arrives after the start time. Thus, a maximum of customers’ orders can be fulfilled, so the rd line outputs .
Regarding the th work plan, baker starting at time cannot fulfill any customer’s order. Thus, the th line outputs .
This sample input satisfies the constraints of Subtasks , and .
Sample 2
This sample input satisfies the constraints of all the subtasks.
Sample 3
This sample input satisfies the constraints of Subtasks , and .
Constraints
- .
- .
- .
- .
- ().
- ().
- ().
- ().
- Given values are all integers.
Subtasks
- (8 points) .
- (12 points) .
- (30 points) ().
- (10 points) ().
- (22 points) .
- (18 points) No additional constraints.