QOJ.ac

QOJ

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

#20806. 乳牛大學

Statistics

Farmer John 計畫開辦一所新的乳牛大學!

fig_1_college_bronze_dec22.png

有 $N$ ($1 \le N \le 10^5$) 頭乳牛可能就讀這所大學。每頭乳牛最多願意支付 $c_i$ ($1 \le c_i \le 10^6$) 的學費。Farmer John 可以設定所有乳牛入學時都必須支付的學費。如果這一學費超過某頭乳牛願意支付的最大金額,這頭乳牛就不會就讀。Farmer John 希望盡可能多地賺錢,以便為教師支付公平的薪資。請確定他最多能賺多少錢,以及應該收取多少學費。

輸入格式

第一行包含 $N$。第二行包含 $N$ 個整數 $c_1, c_2, \dots, c_N$,其中 $c_i$ 是乳牛 $i$ 願意支付的最高學費。

輸出格式

請輸出 Farmer John 能賺到的最大金額以及應該收取的最佳學費。如果有多個方案,輸出最佳學費最小的方案。

注意,本題涉及的整數可能很大,因此可能需要使用 64 位元整數型別(例如 Java 中的 "long",C/C++ 中的 "long long")。

範例

輸入格式 1

4
1 6 4 6

輸出格式 1

12 4

說明

如果 Farmer John 收取 $4$ 的學費,就會有 $3$ 頭乳牛就讀,使他賺到 $3 \cdot 4 = 12$。

子任務

  • 測試點 2 到 4 滿足 $c_i \le 1{,}000$。
  • 測試點 5 到 8 滿足 $N \le 5{,}000$。
  • 測試點 9 到 12 沒有額外限制。

題目作者:Freddie Tang

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.