#P16707. [SEATST 2026] 车辆集结 / Car Gathering
[SEATST 2026] 车辆集结 / Car Gathering
Problem Description
There are cars on a number line, indexed from to . You are given their position list and their fuel consumption rate-per-unit list . Both lists are already sorted in nondecreasing order. However, you do not know which car corresponds to which position or which fuel consumption rate. But you do know that each car has exactly one position and exactly one fuel consumption rate.
That is, there exist two permutations and of length such that the -th car is located at position and has fuel consumption rate .
::::info[What is a permutation of length ?]{open} In this problem, a permutation of length is an array of length such that for all , we have , and for all , we have .
For example, is a permutation of length , but and are not permutations of length . ::::
Given a particular assignment , define the total fuel cost to gather all cars at point as $\text{cost}(P, Q, y) = \sum_{i=0}^{N-1} |X[P[i]] - y| \times C[Q[i]]$.
Given an integer point , define the worst-case fuel cost at point as the maximum total fuel cost over all possible assignments . That is, define $\text{worst}(p) = \max \limits_{P, Q} \text{cost}(P, Q, p)$.
Your task is to find an integer point such that the worst-case fuel cost is minimized. If there are multiple points that achieve the same minimum value of , you may return any one of them.
Implementation Details
You need to implement the following function.
int car_gathering(int N, std::vector<int> X, std::vector<int> C)
- : the number of cars.
- : an array of length describing the car positions, sorted in order.
- : an array of length describing the fuel consumption rates, sorted in order.
- For each testdata, this function is called exactly once.
- This function should return an integer such that, among all integer points, gathering all cars at point minimizes the worst-case fuel cost.
Input Format
N
X[0] X[1] ... X[N - 1]
C[0] C[1] ... C[N - 1]
Output Format
A single integer, representing the return value of car_gathering.
Hint
Sample
Consider the following function call:
car_gathering(3, [-1, 2, 3], [1, 1, 2])
Suppose . It can be proven that the assignments and produce the worst-case fuel cost. That is, $\text{worst}(p) = \text{cost}(P, Q, p) = (|-1 - 1| \times 2) + (|2 - 1| \times 1) + (|3 - 1| \times 1) = 7$. Note that there may be other assignments of and that also produce the worst-case fuel cost, for example and .
It can also be proven that the integer point is the point that makes minimal. Therefore, this function call should return .
Constraints
- .
- For all , .
- For all , .
- For all , .
- For all , .
Subtasks
- ( points) , .
- ( points) .
- ( points) .
- ( points) For all , .
- ( points) No additional constraints.
Translated by ChatGPT 5