PDP-22 (2010) - Phase C' - 1 (lines_man)

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

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 A, the two linesmen start from the center of the field (A/2). Inside the field, the ball moves to various points. The linesmen must monitor the phases, moving only along the sidelines from 0 to A/2 and from A/2 to A, 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 A\;(10 \le A \le 1.000): the length of the field. The second line contains an integer M\;(10 \le M \le 100.000): the number of phases. The next M lines contain an integer Y\;(0 \le Y \le A): 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, L_1 and L_2 (0 \le L_1, L_2 \le 10.000.000): the total distance covered by each linesman. The first moves from 0 to A/2 and the second moves from A/2 to A.

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

pdp-2010-C1.svg

Explanation of the example:

The length of the field is 100, so the first linesman moves between 0 and 50, and the second between 50 and 100 (see diagram). There are a total of 10 phases. Both linesmen start from position 50. In the first four phases (49, 30, 25, and 0), the first linesman runs to position 0, covering a total of 50 meters, while the second linesman remains stationary at position 50. In the fifth phase (50), the first linesman returns to position 50, covering another 50 meters, and the second remains stationary at position 50. In the sixth phase (55), the second linesman runs to position 55, covering 5 meters, while the first remains stationary at position 50. In the seventh phase (40), the second linesman returns to position 50, covering another 5 meters, and the first linesman runs to position 40, covering 10 meters. In the last three phases (30, 20, and 0), the first linesman runs to position 0, covering a total of 40 meters, while the second linesman remains stationary at position 50. The total distances covered by the two linesmen are: L_1 = 50 + 50 + 10 + 40 = 150 and L_2 = 5 + 5 = 10.

Formatting: In the output, each line terminates with a newline character.
Maximum execution time: 1 sec.
Maximum available memory: 16 MB.


Comments

There are no comments at the moment.