On a strip of land of length n there are k air conditioners: the i-th air conditioner is…
- User
On a strip of land of length n there are k air conditioners: the i-th air conditioner is placed in cell a_i (1 ≤ a_i ≤ n). Two or more air conditioners cannot be placed in the same cell (i.e. all a_i are distinct).
Each air conditioner is characterized by one parameter: temperature. The i-th air conditioner is set to the temperature t_i.
Example of strip of length n=6, where k=2, a=[2,5] and t=[14,16].
For each cell i (1 ≤ i ≤ n) find it's temperature, that can be calculated by the formula
Assistant
pythonimport sys def main(): data = list(map(int, sys.stdin.read().split())) ptr = 0 q = data[ptr] ptr += 1 for _ in range(q): n = data[ptr] k = data[ptr + 1] ptr += 2 a = data[ptr:ptr + k] ptr += k t = data[ptr:ptr + k] ptr += k ac = sorted(zip(a, t), key=lambda x: x[0]) left_min = [float('inf')] * (n + 2) current_left = float('inf') j = 0 for i in range(1, n + 1): while j < k and ac[j][0] <= i: current_left = min(current_left, ac[j][1] - ac[j][0]) j += 1 left_min[i] = current_left right_min = [float('inf')] * (n + 2) current_right = float('inf') j = k - 1 for i in range(n, 0, -1): while j >= 0 and ac[j][0] >= i: current_right = min(current_right, ac[j][1] + ac[j][0]) j -= 1 right_min[i] = current_right ans = [] for i in range(1, n + 1): l = left_min[i] + i r = right_min[i] - i ans.append(str(min(l, r))) print(' '.join(ans), end=' ') print() if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.