Logo
(追記) (追記ここまで)

32047번 - Overtaking 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 (추가 시간 없음) 1024 MB1391039275.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

a1an

b1bn

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.

제한

예제 입력 1

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

예제 출력 1

2
0
2

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > Japan Domestic Contest > 2024 Japan Domestic Contest B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /