아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bike Party

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

요약
원형 경로에서 각 정점마다 알코올을 얻고 이동 거리만큼 잃을 때, 마지막 정점에 도착하기 전까지 알코올이 0이 되지 않는 시작 정점을 찾는다.
난이도

보통10점 중 6점

유형
누적 합, 그리디
정답자
아직 제출이 없습니다

문제

There will be multiple great parties tonight after the competition, and Robin is very excited for a night out. At each party Robin will be served one drink containing a fixed amount of alcohol measured in alcohol units, that is consumed immediately upon arrival. The hosts of the parties are not all equally generous. They put different amounts of alcohol in their drinks and some might even serve a non-alcoholic drink!

The parties are located along a circular route. Robin will bike along the circle, visiting every party once, going to bed at the last party which is the same as the first party. Each meter of biking sobers up one unit of alcohol (i.e., the alcohol level is reduced by one). Robin starts completely sober (i.e., at alcohol level zero).

Find a party to start (and end) the journey at such that Robin never becomes sober at any point in time during the night. It is not even allowed to become sober in the moment of arrival to a new location (even if Robin immediately drinks more alcohol upon arrival, the brief moment of soberness would ruin the experience). The only exception is that it is allowed to become sober in the moment when Robin reaches the final party and goes to bed.

Robins alcohol level has no upper limit.

입력

The first line of input contains a single integer 3≤N≤100,0003 \leq N \leq 100\\,000, the number of parties.

Then follow NN lines. Each line, numbered i∈1,2,…,Ni \in \\{ 1, 2, \ldots, N \\}, consists of two integers 0≤A_i≤1090 \leq A\_i \leq 10^9 and 0<D_i≤1090 < D\_i \leq 10^9, where A_iA\_i is the amount of alcohol Robin will receive at the iith party in alcohol units, and D_iD\_i is the distance to the next party along the circle (to party i+1i+1 if i<Ni < N, and to party 11 if i==Ni == N) in meters.

출력

A single integer, the 11-based index of the party where Robin should start the bike party without running out of alcohol.

If no solution exists output a single line with the string "impossible".

If there are multiple possible answers, any will be considered correct.

예제2

  1. 예제 1

    입력
    3
    10 5
    10 5
    10 20
    
    예상 출력
    1
    
  2. 예제 2

    입력
    3
    2 2
    2 2
    2 2
    
    예상 출력
    impossible