QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21049. Coda per la limonata

Statistics

In una calda giornata estiva, Farmer John serve limonata alle $N$ mucche! Tutte, numerate $1 \dots N$, la amano, ma alcune più di altre. La mucca $i$ accetta di aspettare dietro al massimo $w_i$ mucche. Sono nei campi, ma al campanaccio accorreranno subito al banco. Arrivano tutte prima del servizio e mai due contemporaneamente. La mucca $i$ entra se e solo se ci sono già al massimo $w_i$ mucche in coda.

FJ vuole preparare limonata in anticipo senza sprechi. Il numero in coda dipende dall’ordine d’arrivo. Trova il minimo possibile.

Input

La prima riga contiene $N$, la seconda $N$ interi $w_1, w_2, \dots, w_N$ separati da spazi. Sono garantiti $1 \leq N \leq 10^5$ e $0 \leq w_i \leq 10^9$ per ogni mucca $i$.

Output

Stampa il minimo numero che entra tra tutti gli ordini possibili.

Esempi

Input 1

5
7 1 400 2 2

Output 1

3

Spiegazione

Qui il minimo è $3$. Le mucche con $w=7$ e $w=400$ arrivano per prime e aspettano. Quella con $w=1$ se ne va perché ce ne sono già $2$. Poi arrivano quelle con $w=2$: una resta, una se ne va.

Autore del problema: Dhruv Rohatgi

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.