Programming contests

50 Programming Exercise for Beginners

January 2, 2019 12:00 AM – December 31, 2019 12:00 AM

Over Hill and Valley

A tourist hiked through his favorite mountain range, Mátra, over the weekend. Several small settlements were involved in his journey. At the start and every time he arrived at a settlement, he made a note of the number of kilometers he had walked since the last settlement and the population of the settlement he just reached, i.e., the number of people living there.

At the end of his tour, he was curious about the total distance he had taken and the difference between the number of inhabitants of the most populated settlement and the least populated settlement on his trip. Write a program that will make the calculations you need for this.

The input consists of at least two lines, each with two integers: the distance from the last settlement (in meters) and the number of inhabitants of the settlement reached. Your program must process the lines until end-of-file (EOF).

The program should write one line with two integers separated by a space character to the standard output: the length of the trip traveled by the tourist (in meters) and the difference between the number of inhabitants of the most populated settlement and the least populated settlement on his trip. Remember to terminate this line with a newline character.

Sample Input

  1. 0 32056
  2. 3628 617
  3. 6845 1068
  4. 1687 301
  5. 2598 54
  6. 3712 591
  7. 10025 112
  8. 3045 2513
  9. 2174 48
download as text file

Output for Sample Input

  1. 33714 32008
download as text file

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 03/01/2019