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$ 頭の後ろで待つ気があります。今は畑にいますが、鈴が鳴ればすぐ店に押し寄せます。全頭が提供開始前に到着し、同時に着く 2 頭はいません。牛 $i$ は既に並んでいる頭数が $w_i$ 以下の場合に限り並びます。

FJ は無駄を避けて事前にレモネードを用意したいのです。行列に入る頭数は到着順によります。その最小の可能数を求めてください。

入力

最初の行は $N$、2 行目は空白区切りの $N$ 個の整数 $w_1, w_2, \dots, w_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.