Lines man
Since its discovery at the University of Cambridge, football has become the most popular and easiest sport to play. A relatively flat area and a ball are sufficient. According to its rules, the referee moves within the field, and the linesmen move along the sidelines, each on half of the field. If the football field has a length of , the two linesmen start from the center of the field . Inside the field, the ball moves to various points. The linesmen must monitor the phases, moving only along the sidelines from to and from to , respectively.
Problem:
Develop a program in one of the IOI languages that, after reading the length of the field, the number of phases, and the position (length) of each phase, calculates the meters covered by the linesmen during a match. [Note: Linesmen start from the center but do not necessarily return to it at the end of the game.]
Input Files:
The input files named lines_man.in are text files with the following structure: The first line contains an even integer : the length of the field. The second line contains an integer : the number of phases. The next lines contain an integer : the length of the field on which the corresponding phase unfolds.
Output Files:
The output files named lines_man.out are text files with the following structure. They have one line with exactly two numbers, and : the total distance covered by each linesman. The first moves from to and the second moves from to .
Example of Input - Output Files:
STDIN (lines_man.in)
100
10
49
30
25
0
50
55
40
30
20
0
STDOUT (lines_man.out)
150 10
Explanation of the example:
The length of the field is , so the first linesman moves between and , and the second between and (see diagram). There are a total of phases. Both linesmen start from position . In the first four phases (, , , and ), the first linesman runs to position , covering a total of meters, while the second linesman remains stationary at position . In the fifth phase , the first linesman returns to position , covering another meters, and the second remains stationary at position . In the sixth phase , the second linesman runs to position , covering meters, while the first remains stationary at position . In the seventh phase , the second linesman returns to position , covering another meters, and the first linesman runs to position , covering meters. In the last three phases (, , and ), the first linesman runs to position , covering a total of meters, while the second linesman remains stationary at position . The total distances covered by the two linesmen are: and .
Formatting: In the output, each line terminates with a newline
character.
Maximum execution time: 1 sec.
Maximum available memory: 16 MB.
Comments