Orders by city
Make the order as a record, and filter, group and aggregate with query-style processing (C# LINQ, Java streams) instead of loops.
The first line gives the number of orders n and a threshold T, and the next n lines give one order each as "city customer amount".
Keep only orders whose amount is at least T.
Group the remaining orders by city and print "city order_count total top_customer" for each city.
The top customer is the customer of that city's largest order; if several orders share the largest amount, it is the customer of the one that appears first in the input.
On the first line print the number of cities that have remaining orders (print just 0 if no order remains), then one line per city, from the largest total down, with equal totals in dictionary order of the city name.
- Input
- 1 ≤ n ≤ 5000, 1 ≤ T ≤ 1,000,000,000, 1 ≤ amount ≤ 1,000,000,000 (integers).
City and customer names are 1 to 10 lowercase English letters - Output
- the city count c on the first line, then c lines (a total can grow to 5 trillion)
7 10 seoul mina 30 busan jun 9 seoul ari 50 daegu seo 80 busan hana 10 seoul bo 50 busan kim 70
3 seoul 3 130 ari busan 2 80 kim daegu 1 80 seo