P27099 [AtCoder] Red and Blue Medals
省选
题目描述

Problem Description

You have encountered a group of monsters. The group consists of $ N $ monsters, lined up in a single row in front of you. The health of the $ i $-th monster from the front is $ h_i $.

You have decided to defeat all the monsters by using the following two types of attacks:

  • Attack with a sword. This deals damage equal to the remaining health of the frontmost surviving monster.
  • Attack with a spear. This deals $ 1 $ damage to all surviving monsters.

Monsters whose health reaches $ 0 $ disappear.

You have two direct superiors. Each time you perform an attack, you receive a medal as a bonus from your superiors based on the total damage dealt in that single attack.

From the first superior, you receive one red medal if the total damage dealt to the monsters is $ k_1 $ or more.
From the second superior, you receive one blue medal if the total damage dealt to the monsters is $ k_2 $ or more.

Find the maximum possible total number of red and blue medals you can have when all monsters are defeated.

Input Format

The input is given from the standard input in the following format:

$ N $ $ k_1 $ $ k_2 $ $ h_1 $ $\ldots$ $ h_N $

Output Format

Output the answer in one line.

Sample Input and Output

Sample Input #1

4 2 3
3 2 1 1

Sample Output #1

4

Sample Input #2

5 4 5
2 2 2 2 2

Sample Output #2

4

Sample Input #3

15 4 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9

Sample Output #3

16

Notes/Hints

Constraints

  • All inputs are integers.
  • $1 \le N \le 2 \times 10^5$
  • $1 \le k_1 \le k_2 \le 2 \times 10^5$
  • $1 \le h_i \le 2 \times 10^5$

Partial Points

  • If you correctly solve the dataset where $ k_1 = k_2 $, you will be awarded $ 30 $ points.

Sample Explanation 1

You can perform the attacks as follows:
- Attack with a sword. Deal $ 3 $ damage, receiving both a red and a blue medal.
- Attack with a sword. Deal $ 2 $ damage, receiving a red medal.
- Attack with a spear. Deal $ 2 $ damage, receiving a red medal.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 3 3 2 1 1
样例输出
4