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$, והשנייה $N$ שלמים $w_1, w_2, \dots, w_N$ מופרדים ברווחים. מובטח $1 \leq N \leq 10^5$ ו-$0 \leq w_i \leq 10^9$ לכל פרה $i$.

פלט

הדפיסו את מספר המצטרפות המזערי על פני כל סדרי ההגעה האפשריים.

דוגמאות

קלט 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.