#P16707. [SEATST 2026] 车辆集结 / Car Gathering

    ID: 19038 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>贪心二分交互题Special Judge2026

[SEATST 2026] 车辆集结 / Car Gathering

Problem Description

There are NN cars on a number line, indexed from 00 to N−1N - 1. You are given their position list X[0],X[1],…,X[N−1]X[0], X[1], \ldots, X[N - 1] and their fuel consumption rate-per-unit list C[0],C[1],…,C[N−1]C[0], C[1], \ldots, C[N - 1]. 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 PP and QQ of length NN such that the ii-th car is located at position X[P[i]]X[P[i]] and has fuel consumption rate C[Q[i]]C[Q[i]].

::::info[What is a permutation of length NN?]{open} In this problem, a permutation PP of length NN is an array of length NN such that for all 0≤i≤N−10 \le i \le N - 1, we have 0≤P[i]≤N−10 \le P[i] \le N - 1, and for all 0≤i<j≤N−10 \le i < j \le N - 1, we have P[i]≠P[j]P[i] \ne P[j].

For example, [2,1,0][2, 1, 0] is a permutation of length 33, but [1,2,3][1, 2, 3] and [2,0,2][2, 0, 2] are not permutations of length 33. ::::

Given a particular assignment (P,Q)(P, Q), define the total fuel cost to gather all cars at point yy as $\text{cost}(P, Q, y) = \sum_{i=0}^{N-1} |X[P[i]] - y| \times C[Q[i]]$.

Given an integer point pp, define the worst-case fuel cost at point pp as the maximum total fuel cost over all possible assignments (P,Q)(P, Q). That is, define $\text{worst}(p) = \max \limits_{P, Q} \text{cost}(P, Q, p)$.

Your task is to find an integer point pp such that the worst-case fuel cost worst(p)\text{worst}(p) is minimized. If there are multiple points pp that achieve the same minimum value of worst(p)\text{worst}(p), 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)
  • NN: the number of cars.
  • XX: an array of length NN describing the car positions, sorted in order.
  • CC: an array of length NN describing the fuel consumption rates, sorted in order.
  • For each testdata, this function is called exactly once.
  • This function should return an integer pp such that, among all integer points, gathering all cars at point pp 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 p=1p = 1. It can be proven that the assignments P=[0,1,2]P = [0, 1, 2] and Q=[2,1,0]Q = [2, 1, 0] 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 PP and QQ that also produce the worst-case fuel cost, for example P=[2,1,0]P = [2, 1, 0] and Q=[2,1,0]Q = [2, 1, 0].

It can also be proven that the integer point p=1p = 1 is the point that makes worst(p)\text{worst}(p) minimal. Therefore, this function call should return 11.

Constraints

  • 1≤N≤10 000 0001 \le N \le 10\ 000\ 000.
  • For all 0≤i≤N−10 \le i \le N - 1, −109≤X[i]≤109-10^9 \le X[i] \le 10^9.
  • For all 0≤i≤N−10 \le i \le N - 1, 0≤C[i]≤1000 \le C[i] \le 100.
  • For all 0≤i<j≤N−10 \le i < j \le N - 1, X[i]≤X[j]X[i] \le X[j].
  • For all 0≤i<j≤N−10 \le i < j \le N - 1, C[i]≤C[j]C[i] \le C[j].

Subtasks

  1. (1010 points) N≤1000N \le 1000, ∣X[i]∣≤103|X[i]| \le 10^3.
  2. (2323 points) N≤100 000N \le 100\ 000.
  3. (1717 points) N≤1 000 000N \le 1\ 000\ 000.
  4. (3131 points) For all 0≤i≤N−10 \le i \le N - 1, C[i]≤1C[i] \le 1.
  5. (1919 points) No additional constraints.

Translated by ChatGPT 5