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 inf = float('inf') left = [inf] * (n + 2) right = [inf] * (n + 2) for pos, temp in zip(a, t): if left[pos] > temp: left[pos] = temp if right[pos] > temp: right[pos] = temp for i in range(1, n + 1): left[i] = min(left[i], left[i - 1] + 1) for i in range(n, 0, -1): right[i] = min(right[i], right[i + 1] + 1) res = [] for i in range(1, n + 1): res.append(str(min(left[i], right[i]))) print(' '.join(res), end=' \n') 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.