| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 8 초 (추가 시간 없음) | 1024 MB | 139 | 103 | 92 | 75.410% |
Two athletes run a long-distance race, but the race is different from usual athletics events. They run for a predetermined duration, and the one who runs longer will be the winner. At every minute after the start, the distances both runners ran in the previous one minute are recorded. You are expected to write a program that, given the record of a race, counts the number of overtakings by either runner during the race. You should assume that both runners keep constant paces for every one minute before their distances are recorded.
Here, the term overtaking stands for the event where the runner previously behind takes the lead. Note that, before overtaking, the two runners may run side by side for a while, during which neither takes the lead. Figure B-1 shows the times and the positions of two runners for the third dataset of Sample Input. The number of overtakings in this case is two.
Figure B-1: The third dataset of Sample Input
The input consists of multiple datasets, each in the following format.
n
a1 ⋯ an
b1 ⋯ bn
n is an integer between 2 and 1000, inclusive. It represents the duration of the race in minutes. Each of ak (k = 1, …, n) is an integer between 1 and 1000, inclusive. It represents the distance the first runner ran between k − 1 minutes and k minutes after the start of the race, in meters. Similarly, bk (k = 1, …, n) represent the distances the second runner ran.
The end of the input is indicated by a line consisting of a zero. The number of datasets does not exceed 100.
For each dataset, output the number of overtakings on a line.
3 5 15 5 10 5 15 9 10 10 10 10 10 10 10 10 10 5 15 10 5 15 10 5 15 10 9 10 10 10 5 15 10 10 10 10 5 15 10 10 10 10 5 15 10 0
2 0 2
ICPC > Regionals > Asia Pacific > Japan > Japan Domestic Contest > 2024 Japan Domestic Contest B번