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

10004번 - Bytecomputer 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB93413645.000%

문제

A sequence of n integers x1,x2,…,xn from the set {-1,0,1} is given. The bytecomputer is a device that allows the following operation on the sequence: incrementing xi+1 by xi for any 1 ≤ i ≤ n. There is no limit on the range of integers the bytecomputer can store, i.e., each xi can (in principle) have arbitrarily small or large value.

Program the bytecomputer so that it transforms the input sequence into a non-decreasing sequence (i.e., such that x1 ≤ x2 ≤ … ≤ xn) with the minimum number of operations.

입력

The first line of the standard input holds a single integer n (1 ≤ n ≤ 1,000,000), the number of elements in the (bytecomputer's) input sequence.

The second line contains n integers x1,x2,…,xn (xi ∈ {-1,0,1}) that are the successive elements of the (bytecomputer's) input sequence, separated by single spaces.

출력

The first and only line of the standard output should give one integer, the minimum number of operations the bytecomputer has to perform to make its input sequence non-decreasing, of the single word BRAK (Polish for none) if obtaining such a sequence is impossible.

제한

예제 입력 1

6
-1 1 0 -1 0 1

예제 출력 1

3

힌트

with three operations, the bytecomputer can obtain the sequence -1,-1,-1,-1,0,1.

출처

Olympiad > Polish Olympiad in Informatics > POI 2012/2013 > Stage 3 2번

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

출처

대학교 대회

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

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