← 返回 tesla 的题目列表Implement a Speed-Limit RL Reward for Batched Trajectories (10Hz)
类型:online_judge
Implement a speed-limit reward function for RL.
Given:
traj with shape [batch, num_waypoint, 2] sampled at 10Hz. Assume traj[b][t][0] is speed v(t) (same unit as the speed limit) and traj[b][t][1] is an unused feature.
speed_limit is either:
a scalar L (constant limit), or
an array L[t] of length num_waypoint (time-varying limit).
Output a scalar reward R[b] per batch:
dt = 0.1 seconds.
over(t) = max(0, v(t) - L(t)).
Reward is the negative integrated overspeed:
[ R[b] = - \sum_{t=0}^{num_waypoint-1} over(t) \cdot dt ]
Input (stdin)
Line 1: B N mode (mode=0 scalar limit, mode=1 per-timestep limit)
Line 2: scalar L if mode=0, else N numbers L[0..N-1]
Next B lines: each has 2*N numbers: v0 f0 v1 f1 ... v{N-1} f{N-1}
Output (stdout)
Print B lines, each a single number R[b].
Constraints
1 <= B <= 2000
1 <= N <= 200000 (linear O(B*N) expected)
Example
Input:
1 5 0
10
8 0 12 0 10 0 11 0 9 0
Output:
-0.3
Example
Input
1 5 0
10
8 0 12 0 10 0 11 0 9 0
Output
-0.30000000000000004