Bitcoin Bubble

시간 제한2초메모리 제한2048 MB

요약
각 가격이 여러 날 연속 유지되는 구간들이 시간 순서대로 주어질 때, 날짜 x를 품으면서 그날 가격보다 싼 날이 없는 가장 넓은 구간 [a,b]를 골라 가격(x)와 길이의 곱의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
스택, 그리디, 배열
정답자
아직 제출이 없습니다

문제

These days, all eyes and money are on crypto. The stakes are high and a team of experts, which call themselves the FPC (Fabulous People of Crypto) are on the verge of a big move. They call their move "The Bubble".

The Bubble will work as follows: one day, the FPC will release a set of classified information that will shake the market to its roots. That day, call it xx, will be the epicenter of their move. To measure the impact of The Bubble, consider the longest sequence of consecutive days, starting on day aa and ending on day bb (a≤x≤ba\leq x\leq b), for which Bitcoin's price is never lower than its price on day xx. The impact is measured as the length of this sequence in days multiplied by the price of Bitcoin on day xx. The starting day and the end day of The Bubble's impact should be within the boundaries of the period the FPC know the price for.

There is only one catch: despite anticipating Bitcoin's price for the foreseeable future, the FPC lack the most fabulous skill in the world: programming. Help them measure the biggest possible impact of The Bubble, given that they release the shocking information on an optimal day.

입력

The input consists of:

  • A line with a single integer nn (1≤n≤5⋅1041\leq n\leq 5\cdot 10^4), the number of price anticipations for Bitcoin.
  • nn lines, each containing two integers pp and dd (0≤p≤2⋅1090\leq p\leq 2\cdot 10^9 and 1≤d≤5⋅1041\leq d\leq 5\cdot 10^4), representing the price and the number of days the price lasts for.

Price information is given in chronological order.

출력

Output a single number, the biggest impact The Bubble can have.

예제2

  1. 예제 1

    입력
    4
    3 2
    9 4
    5 2
    7 4
    
    예상 출력
    50
    
  2. 예제 2

    입력
    10
    5 5
    8 1
    8 3
    9 1
    0 6
    1 6
    1 5
    6 2
    6 5
    9 6
    
    예상 출력
    78