← 返回 nvidia 的题目列表Detect Temperature Spike from (timestamp, temperature) pairs
类型:online_judge
Given a time-ordered list of (timestamp, temperature) data points, detect whether there exists a temperature spike.
Definition: a spike occurs if at some index i, the temperature temp[i] increases significantly compared to a previous reading within a short time window.
Rules:
You are given integers window (seconds) and delta (temperature threshold).
If there exist indices j < i such that:
timestamp[i] - timestamp[j] <= window
temperature[i] - temperature[j] >= delta then output true; otherwise output false.
Input (stdin):
First line: n window delta
Next n lines: t_i temp_i with strictly increasing t_i
Output (stdout):
One line: true or false
Constraints:
1 <= n <= 2e5
0 <= t_i <= 1e9
-1e6 <= temp_i <= 1e6
Requirement: better than O(n^2) time.
Example
Input
5 10 5
0 30
3 31
6 33
9 40
20 39
Output
true