Dividing apples

면접 대비

시간 제한1초메모리 제한1024 MB

요약
어느 바구니 뒤에 경계를 두어 왼쪽 합과 오른쪽 합의 차가 최소가 되게 하는 위치를 구한다.
난이도

쉬움10점 중 3점

유형
누적 합, 배열
정답자
아직 제출이 없습니다

문제

NN baskets are lined up, numbered 1…N1 \ldots N from left to right. The basket number ii contains K_iK\_i apples. John and Mary want to draw a line between two baskets, and then John would get all the baskets to the left of the line and Mary all the baskets to the right of the line. Help them draw the line to divide the apples as equally as possible!

입력

The first line of input contains NN, the number of baskets (2≤N≤1,000,0002 \le N \le 1\\,000\\,000). Each of the following NN lines contains an integer K_iK\_i: the number of apples in basket number ii (1≤i≤N1 \le i \le N, 0≤K_i≤10,0000 \le K\_i \le 10\\,000).

출력

The only line of output should contain a single integer: the number of the basket to the right of which the line should be drawn, so that the absolute value of the difference between the number of apples John gets, and the number of apples Mary gets, would be as small as possible. If there are multiple possible answers, output any one of them.

예제1

  1. 예제 1

    입력
    7
    4
    2
    10
    2
    9
    3
    7
    
    예상 출력
    4