A city bike-share operator monitors k docking stations over the course of a day. Every station starts the day perfectly balanced, at a net tally of zero. Throughout the day the system logs a stream of events; each event names a station and a signed integer delta describing how that station's bike count changed relative to where it started (a positive delta means bikes accumulated there faster than they left, a negative delta means the opposite). Given all of the day's events and a surplus threshold t, the operator wants to identify every station whose final net tally is strictly greater than t — these are the stations that have built up too great a surplus and are candidates for having bikes physically redistributed elsewhere overnight.
k t, the number of stations and the surplus threshold.k lines each contain stationId name: a distinct integer station identifier and the station's name (a non-empty string of letters, digits, and underscores, at most 20 characters, no spaces).m, the number of events.m lines each contain stationId delta: the identifier of the affected station (guaranteed to be one of the identifiers listed above) and a nonzero integer delta.First print a single integer c, the number of stations whose final tally is strictly greater than t. Then print c lines, one per such station sorted by increasing stationId, each containing stationId name tally where tally is that station's final net tally.
Example 1
Input
3 5 101 Riverside 102 Uptown 103 Marina 4 101 3 101 4 102 -2 103 10
Expected
2 101 Riverside 7 103 Marina 10
Explanation
Riverside's events (3 and 4) sum to a tally of 7, Uptown's single event gives a tally of -2, and Marina's single event gives a tally of 10. With threshold 5, only Riverside (7 > 5) and Marina (10 > 5) qualify, so the output is 2 followed by "101 Riverside 7" and "103 Marina 10" in ascending id order.
Example 2
Input
2 0 201 Eastgate 202 Westgate 2 201 -1 202 1
Expected
1 202 Westgate 1
Explanation
Eastgate's tally is -1 and Westgate's tally is 1. With threshold 0, only Westgate's tally (1 > 0) qualifies, so the output is 1 followed by "202 Westgate 1".
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 →