A disaster-relief charity tracks every grant-disbursement request it receives from its country offices. Each entry in the request log records the calendar date the request was filed, the country office that filed it, whether headquarters approved or declined it, and the amount (in whole currency units) that was requested. At the end of every reporting cycle, the finance team needs, for every month and country office that appears in the log, both the total number and total amount of requests filed, and, among those, the number and amount that were actually approved.
m, the number of request-log entries.m lines contains one entry as four space-separated tokens: date country status amount, where
date is a calendar date in YYYY-MM-DD format,country is a token of uppercase letters identifying the country office,status is either approved or declined,amount is a positive integer.For every distinct (month, country office) pair that appears at least once in the log, print one line:
YYYY-MM COUNTRY total_count total_amount approved_count approved_amount
where YYYY-MM is the year and month, total_count/total_amount are the number and sum of amounts of ALL requests filed by that country office in that month, and approved_count/approved_amount are the number and sum of amounts among only the approved ones. Print the lines ordered by month ascending, and by country office (lexicographically) ascending within a month.
date is a valid calendar date between 2000-01-01 and 2029-12-31.country consists of 2 to 20 uppercase English letters.Example 1
Input
5 2018-12-18 USA declined 1000 2018-12-19 USA approved 2000 2018-12-20 USA declined 500 2019-01-01 USA approved 100 2019-01-02 USA declined 200
Expected
2018-12 USA 3 3500 1 2000 2019-01 USA 2 300 1 100
Explanation
In December 2018, USA filed three requests (declined 1000, approved 2000, declined 500): total_count 3, total_amount 3500, and only the approved one contributes to approved_count 1, approved_amount 2000. In January 2019, USA filed two requests (approved 100, declined 200): total_count 2, total_amount 300, approved_count 1, approved_amount 100.
Example 2
Input
3 2020-05-01 USA approved 100 2020-05-02 UAE declined 300 2020-05-03 UAE approved 200
Expected
2020-05 UAE 2 500 1 200 2020-05 USA 1 100 1 100
Explanation
In May 2020, UAE filed two requests (declined 300, approved 200): total_count 2, total_amount 500, approved_count 1, approved_amount 200. USA filed one approved request of 100. Because UAE sorts before USA lexicographically, the UAE line is printed first even though its first request comes after USA's in the log.
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 →