#P14004. [eJOI 2025] Vacation
[eJOI 2025] Vacation
题目描述
Anton and his friends are planning a vacation together. They have already chosen the location; however, the dates are harder to agree on.
All friends have submitted in advance the days they plan to take off work. Friend originally scheduled their time off from day to day , inclusive. To maximize the time they can spend together, each friend may adjust their time off by shifting it earlier or later. Specifically, the -th friend can choose an integer and move their time off to the interval . A positive means taking time off later than originally planned, a negative means earlier, and means keeping the original schedule.
The friends recognize that their bosses will not like the disruption caused by their changes. Therefore, they will only move their days off in a way such that the total movement of the intervals does not exceed some integer . Formally, they have to satisfy .
Help the friends figure out the maximum number of days all of them can be together if they change their schedules optimally.
Implementation details
You should implement the function plan_vacation
:
int plan_vacation(int N, std::vector<int> L, std::vector<int> R, long long K)
- : the number of friends
- : a vector of positive integers, each of which denotes the first day off originally scheduled for that friend;
- : a vector of positive integers, each of which denotes the last day off originally scheduled for that friend;
- : the maximum allowed value of .
This function will be called once for each test. It has to return the maximum number of days all friends can be together or 0 if that isn't possible at all.
输入格式
The input format is the following:
- line 1: two integers – the values of and .
- lines 2 to : two integers – and .
输出格式
The output format is the following:
- line 1: one integer – the return value of the call.
3 3
1 3
5 9
2 5
2
提示
Example
Consider the following call:
plan_vacation(3, {1, 5, 2}, {3, 9, 5}, 3)
The friends have requested the following intervals of days off: , , . Therefore, friend 0 can move their time off to 2 days later and friend 1 their time off to 1 day earlier to get , , . Then, all friends would be available on day 4 and day 5, which results in 2 days in common. It can be proven that they can't do better with . Therefore, the function should return 2.
Constraints
Subtasks
Subtask | Points | Required subtasks | Additional constraints |
---|---|---|---|
0 | - | The example. | |
1 | 7 | ||
2 | 11 | 1 | |
3 | 6 | - | |
4 | 13 | 0 | , , |
5 | 18 | ||
6 | 29 | 0, 4, 5 | |
7 | 16 | 0 - 6 | - |