QOJ.ac

QOJ

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

#21049. 레모네이드 줄

Statistics

더운 여름날 Farmer John은 소 $N$마리에게 레모네이드를 준다! 번호 $1 \dots N$인 모든 소가 좋아하지만 좋아하는 정도는 다르다. 소 $i$는 최대 $w_i$마리 뒤에서 기다릴 수 있다. 지금은 들판에 있지만 종이 울리면 바로 판매대로 몰려온다. 모두 제공 시작 전에 도착하며 동시에 도착하는 둘은 없다. 소 $i$는 줄에 이미 최대 $w_i$마리가 있을 때만, 그리고 그 경우 반드시 합류한다.

FJ는 낭비 없이 미리 레모네이드를 준비하고 싶다. 합류 수는 도착 순서에 달려 있다. 가능한 최소 수를 구하라.

입력

첫 줄에 $N$, 둘째 줄에 공백으로 구분한 정수 $w_1, w_2, \dots, w_N$이 $N$개 있다. $1 \leq N \leq 10^5$와 모든 소 $i$에 대한 $0 \leq w_i \leq 10^9$가 보장된다.

출력

모든 도착 순서 중 줄에 합류하는 최소 소 수를 출력하라.

예제

입력 1

5
7 1 400 2 2

출력 1

3

참고

여기서는 최소 $3$마리다. $w=7$, $w=400$인 소가 먼저 와서 기다린다. $w=1$인 소는 이미 $2$마리가 있어 떠난다. 다음으로 $w=2$인 소가 와서 하나는 남고 하나는 떠난다.

문제 출제: 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.