A boardwalk runs a summer-long fleet of numbered concession stands. Whenever the boardwalk operator changes a stand's listed price, the change is written into a log entry containing the stand's id, the new price, and the day number on which the change takes effect. A stand keeps the boardwalk's default opening price of 10 for every day up to and including the day before its first recorded change. Given the full log and a single query day, report the price that was actually in effect at every stand that appears anywhere in the log, on that query day: the price fixed by that stand's most recent change on or before the query day, or 10 if none of its changes happened on or before that day.
n and q: the number of log entries and the query day.n lines contains three integers standId, newPrice, and day, describing one log entry: on day day, stand standId's price became newPrice. No two log entries share the same (standId, day) pair.Print one line per distinct standId that appears anywhere in the log, in strictly increasing order of standId. Each line contains the standId followed by a single space and its price on day q.
Example 1
Input
3 4 1 20 2 1 15 4 2 30 1
Expected
1 15 2 30
Explanation
Stand 1 has two changes on or before day 4 (day 2 to price 20, day 4 to price 15); the most recent is day 4, so its price is 15. Stand 2's only change is on day 1, which is on or before day 4, so its price is 30.
Example 2
Input
2 1 5 40 3 5 25 5
Expected
5 10
Explanation
Stand 5's earliest recorded change happens on day 3, which is after the query day 1, so no change has taken effect yet and the stand still shows the default price of 10.
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 →