QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#1172. Junkyeom 的競賽

统计

Junkyeom 和他的朋友們 Myung 與 Myeong 計畫舉辦一場程式設計競賽,獎項包含一面金牌(第一名)、兩面銀牌(第二、三名)以及四面銅牌(第四、五、六、七名)。

贊助商為競賽提供了 $N$ 張禮物卡,其中第 $i$ 張卡的價值為 $A_i$。每位獲獎者將獲得一張卡片。令 $P_i$ 為頒發給第 $i$ 名參賽者的卡片價值。若滿足以下兩個不等式,則該分配被視為「公平」的:

$$P_1 \geq P_2 \geq P_3 \geq P_4 \geq P_5 \geq P_6 \geq P_7$$

$$P_1 < P_2 + P_3 < P_4 + P_5 + P_6 + P_7$$

給定 $A_i$ 的值,請判斷是否存在公平的獎項分配方式。若存在,請輸出公平分配下 $P_i$ 的最大總和。

輸入格式

第一行包含一個整數 $N$,代表禮物卡的數量 ($7 \leq N \leq 5 \cdot 10^5$)。

第二行包含 $N$ 個整數 $A_i$:代表各張卡的價值 ($1 \leq A_i \leq 2 \cdot 10^8$)。

輸出格式

若不存在公平的獎項分配方式,請輸出 $-1$。

否則,請輸出一個整數:公平分配下禮物卡價值的最大總和。

範例

範例輸入 1

7
1 2 3 4 5 6 7

範例輸出 1

-1

範例輸入 2

8
1 2 3 4 5 6 7 8

範例輸出 2

35

範例輸入 3

10
5 5 5 5 5 5 10 5 5 5

範例輸出 3

35

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.