#K281. Car Trip Distance Calculation
Car Trip Distance Calculation
Car Trip Distance Calculation
You are given the trip data of multiple cars collected through several test cases. Each test case begins with an integer T which represents the number of test cases. For each test case, the first line contains an integer N denoting the number of car records, followed by N lines. Each line contains a car identifier followed by several space‐separated integers representing the distances covered in individual trips by that car.
Your task is to compute the total distance traveled by each car. For every test case, calculate the sum of all trip distances for every car and then output the results in alphabetical order by the car identifier. All the answers from different test cases should be concatenated and printed sequentially.
Note: If a test case has N = 0 (i.e. no car data), it produces no output.
inputFormat
The input is read from standard input (stdin). It begins with an integer T denoting the number of test cases. For each test case:
- The first line contains an integer N, the number of cars.
- Each of the following N lines contains a car record in the format:
car_id d1 d2 ... dk
, wherecar_id
is a string andd1, d2, ..., dk
are positive integers representing trip distances.
outputFormat
Output to standard output (stdout) one line per car record. Each line should contain the car identifier and the total distance traveled by that car separated by a space. The car records must be sorted in alphabetical order by the car identifier. All results from all test cases are concatenated, maintaining the sorted order within each test case.## sample
2
3
carA 10 20 30
carB 15 25
carC 5 10 15 20
2
carX 50
carY 30 60 10
carA 60
carB 40
carC 50
carX 50
carY 100
</p>