Daily Balance Snapshot
An internal finance dashboard wants to display the end-of-day balance for every account that appeared in today's batch of ledger postings. You receive the day's postings as a flat list and must compute one final number per account in one pass.
Problem
You are given a list of postings. Each posting is a pair (account_id, delta) where delta is a signed integer representing money credited (positive) or debited (negative) from the account on that line. Return the end-of-day balance for each account that appears at least once in the postings, sorted by account_id ascending.
Input
An integer n (1 ≤ n ≤ 10^5) followed by n pairs. Each pair has a string account_id (length 1–16, lowercase alphanumeric) and an integer delta (−10^9 ≤ delta ≤ 10^9).
Output
A list of (account_id, balance) pairs sorted lexicographically by account_id. Each balance fits in a signed 64-bit integer.
Constraints
- 1 ≤ n ≤ 100,000
- |delta| ≤ 1,000,000,000 per line
- Account ids are case-sensitive ASCII strings up to 16 chars
- An account with a net balance of 0 must still appear if it had any postings
Examples
Example 1
Input
5 acme +500 beta -200 acme -100 beta +200 gamma +1000
Output
acme 400 beta 0 gamma 1000
acme: 500 − 100 = 400. beta: −200 + 200 = 0 (still listed because it had postings). gamma: +1000.
Example 2
Input
3 x +1 x -1 x -1
Output
x -1
Single account with three postings. Net = −1.