#P11049. [IOI 2024] 尼罗河船运
[IOI 2024] 尼罗河船运
Background
This is an interactive problem. You only need to implement the function required in the code.
Your code must not include any additional header files, and you do not need to implement the main function.
This problem only supports submissions in C++. However, please do not use C++14 (GCC 9).
Problem Description
You want to transport handicrafts through the Nile. These handicrafts are numbered from to . The weight of handicraft () is .
To transport these handicrafts, you use special boats. Each boat can carry at most two handicrafts.
- If you decide to put a single handicraft on a boat, its weight can be arbitrary.
- If you want to put two handicrafts on the same boat, you must ensure the boat is balanced. Specifically, if handicrafts and () have an absolute weight difference of at most , i.e., , then you may place them on the same boat.
You must pay to transport a handicraft, and the cost depends on how many handicrafts are carried on the same boat. The transport cost for handicraft () is:
- , if you transport handicraft alone on a boat, or
- , if you transport handicraft together with another handicraft.
Note that in the second case, you pay the cost for both handicrafts on the boat. Specifically, if you decide to transport handicrafts and () on the same boat, you need to pay .
The cost of transporting a handicraft alone on a boat is always higher than transporting it together with another handicraft, so for every satisfying , we have .
Unfortunately, because the Nile is unpredictable, the value of changes frequently. Your task is to answer queries, numbered from to . The queries are described by an array of length . The answer to query () is the minimum total cost to transport all handicrafts when is equal to .
Input Format
The grader reads the input data in the following order:
N
W[0] A[0] B[0]
W[1] A[1] B[1]
...
W[N-1] A[N-1] B[N-1]
Q
E[0]
E[1]
...
E[Q-1]
Output Format
The grader outputs the following in order:
R[0]
R[1]
...
R[S-1]
Here, is the length of the returned array from calculate_costs.
5
15 5 1
12 4 2
2 5 2
10 6 3
21 3 2
3
5
9
1
16
11
23
Hint
Implementation Details
You need to implement the following function.
std::vector<long long> calculate_costs(
std::vector<int> W, std::vector<int> A,
std::vector<int> B, std::vector<int> E)
- , , : integer arrays of length , giving the weights and costs of the handicrafts.
- : an integer array of length , giving the value of in each query.
- The function should return an array containing integers, giving the minimum total transport cost, where corresponds to the cost when equals (for each satisfying ).
- For each test case, this function is called exactly once.
Constraints
- .
- .
- For each satisfying , .
- For each satisfying , .
- For each satisfying , .
Subtasks
| Subtask | Points | Additional Constraints |
|---|---|---|
| 1 | ; ; for each satisfying , | |
| 2 | ; for each satisfying , | |
| 3 | ; for each satisfying , and | |
| 4 | ; | |
| 5 | ||
| 6 | For each satisfying , and | |
| 7 | No additional constraints. |
Hint
Consider the following call.
calculate_costs([15, 12, 2, 10, 21],
[5, 4, 5, 6, 3],
[1, 2, 2, 3, 2],
[5, 9, 1])
In this example, we have handicrafts and queries.
In the first query, . You can put handicrafts and on the same boat (because ), and put all other handicrafts on separate boats. This makes the minimum total cost to transport all handicrafts equal to .
In the second query, . You can put handicrafts and on the same boat (because ), and put handicrafts and on the same boat (because ). The remaining handicraft is transported alone on a boat. This makes the minimum total cost to transport all handicrafts equal to .
In the last query, . You need to transport each handicraft alone on a boat. This makes the minimum total cost to transport all handicrafts equal to .
Therefore, the function should return .
Translated by ChatGPT 5