Mind the Gap | 프로그래밍의 벗 PivotOJ
PivotOJ

Mind the Gap

시간 제한: 2000ms메모리 제한: 512MB출처: ICPC 2020-2021 Northwestern Russia Regional ContestBOJ 20244

문제

Mika is playing the Mind game with her friends. 

The game is played with cards, a single integer value is written on each card. All values written on the cards are distinct. Players keep playing cards, building a single pile of cards on the table. Initially the pile contains a single card with integer 00 on it. Each player is given a single card with a value from 11 to 10910^9. Then players start playing the cards in any order. When a player plays a card, they place it on the top of the pile. The goal is to play all the cards in such a way that the card values increase from the bottom to the top. If any player didn't play their card or the pile is not increasing, the players lose, otherwise they win. No communication between players is allowed after the cards are distributed.

Mika and her friends came up with a strategy. They agree on a single integer dd before the game. During the game, if a player's card value is xx, and the top value of the pile is yy, such that xydx - y \le d, then the player plays their card. If xy>dx - y > d, the player doesn't play their card. If several players play their cards at the same time, these cards might be placed on the top of the pile in any order, and this order is not controlled by the players.

You are given the card values that are going to be distributed to the players. Your task is to find an integer dd for the players' strategy that guarantees them a win.

입력

The first line contains an integer nn --- the number of players playing the Mind game (3n1000003 \le n \le 100\,000).

The second line contains nn integers --- the card values distributed to the players.

All given card values are distinct, positive and don't exceed 10910^9.

출력

Print a single integer dd that Mika and her friends should use to guarantee a win in the game using their strategy. If no such dd exists, print 00. If several values of dd exist, print any of them.

힌트

In the first example d=3d = 3 would also be a correct answer.

예제

예제 1

입력
5
5 13 2 10 8
출력
4

예제 2

입력
5
4 13 2 8 7
출력
0
코드를 제출하려면 로그인하세요.