A spacecraft's life-support computer keeps a log of cabin temperature readings. Each log entry records a unique entry id, the mission day it was taken on, and the temperature reading (an integer, which may be negative). Entries are not necessarily stored in chronological order.
An entry is a warming entry if the log also contains a reading for the mission day immediately before it (mission day minus one) and this entry's temperature is strictly greater than that previous day's temperature. Find every warming entry.
N — the number of log entries.N lines: each containing three space-separated integers id, day, and temp — the entry's id, mission day, and temperature reading.K — the number of warming entries.K lines: the id of each warming entry, one per line, ordered by increasing mission day.id values are distinct, and all day values are distinct.Example 1
Input
4 1 1 10 2 2 25 3 3 20 4 4 30
Expected
2 2 4
Explanation
Day 1 read 10 degrees. Day 2 (id 2) read 25, which is warmer than day 1's 10, so id 2 is a warming entry. Day 3 (id 3) read 20, which is cooler than day 2's 25, so it does not qualify. Day 4 (id 4) read 30, warmer than day 3's 20, so id 4 qualifies. Ordered by day, the warming entries are id 2 (day 2) then id 4 (day 4).
Example 2
Input
3 11 8 60 10 5 50 12 6 55
Expected
1 12
Explanation
The entries are logged out of order, but sorting by day gives day 5 (id 10, 50 degrees), day 6 (id 12, 55 degrees), and day 8 (id 11, 60 degrees). Day 6 is exactly one day after day 5 and is warmer (55 > 50), so id 12 qualifies. Day 8 has no logged entry for day 7, so it cannot be compared and does not qualify. Only id 12 qualifies.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →