CF611E.New Year and Three Musketeers

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Do you know the story about the three musketeers? Anyway, you must help them now.

Richelimakieu is a cardinal in the city of Bearis. He found three brave warriors and called them the three musketeers. Athos has strength a, Borthos strength b, and Caramis has strength c.

The year 2015 is almost over and there are still n criminals to be defeated. The i-th criminal has strength t__i. It's hard to defeat strong criminals — maybe musketeers will have to fight together to achieve it.

Richelimakieu will coordinate musketeers' actions. In each hour each musketeer can either do nothing or be assigned to one criminal. Two or three musketeers can be assigned to the same criminal and then their strengths are summed up. A criminal can be defeated in exactly one hour (also if two or three musketeers fight him). Richelimakieu can't allow the situation where a criminal has strength bigger than the sum of strengths of musketeers fighting him — a criminal would win then!

In other words, there are three ways to defeat a criminal.

  • A musketeer of the strength x in one hour can defeat a criminal of the strength not greater than x. So, for example Athos in one hour can defeat criminal i only if t__i ≤ a.
  • Two musketeers can fight together and in one hour defeat a criminal of the strength not greater than the sum of strengths of these two musketeers. So, for example Athos and Caramis in one hour can defeat criminal i only if t__i ≤ a + c. Note that the third remaining musketeer can either do nothing or fight some other criminal.
  • Similarly, all three musketeers can fight together and in one hour defeat a criminal of the strength not greater than the sum of musketeers' strengths, i.e. t__i ≤ a + b + c.

Richelimakieu doesn't want musketeers to fight during the New Year's Eve. Thus, he must coordinate their actions in order to minimize the number of hours till all criminals will be defeated.

Find the minimum number of hours to defeat all criminals. If musketeers can't defeat them all then print "-1" (without the quotes) instead.

你听说过三个火枪手的故事吗?无论如何,你现在必须帮助他们。

里切利马克耶夫是熊城的一位红衣主教。他找到了三位勇敢的战士,并称他们为“三个火枪手”。阿多斯的力量为 aa,波尔多斯的力量为 bb,阿拉密斯的力量为 cc。

2015 年即将结束,仍有 nn 名罪犯有待制服。第 ii 名罪犯的力量为 tit_i。制服力量强大的罪犯十分困难——火枪手们或许不得不联手作战才能成功。

里切利马克耶夫将协调火枪手们的行动。每小时中,每位火枪手可选择无所事事,或被指派去对付一名罪犯。两名或三名火枪手可被同时指派至同一罪犯,此时他们的力量相加。一名罪犯必须在恰好一小时内被制服(即使由两名或三名火枪手共同对付)。里切利马克耶夫不允许出现罪犯力量大于与其对战的火枪手力量总和的情形——否则罪犯将获胜!

换言之,制服一名罪犯共有三种方式:

  • 一名力量为 xx 的火枪手可在一小时内制服力量不超过 xx 的罪犯。例如,阿多斯在一小时内仅当 ti≤at_i \leq a 时才能制服第 ii 名罪犯。
  • 两名火枪手可联手作战,在一小时内制服力量不超过这两人力量之和的罪犯。例如,阿多斯与阿拉密斯在一小时内仅当 ti≤a+ct_i \leq a + c 时才能制服第 ii 名罪犯。注意:第三位未参与的火枪手可选择无所事事,或去对付其他罪犯。
  • 同理,三名火枪手可联手作战,在一小时内制服力量不超过三人力量总和的罪犯,即 ti≤a+b+ct_i \leq a + b + c。

里切利马克耶夫不希望火枪手们在除夕夜作战。因此,他必须统筹安排其行动,以最小化制服所有罪犯所需的小时数。

求制服全部罪犯所需的最少小时数;若无法全部制服,则输出 -1(不含引号)。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of criminals.

The second line contains three integers a, b and c (1 ≤ a, b, c ≤ 108) — strengths of musketeers.

The third line contains n integers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ 108) — strengths of criminals.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 200 0001 ≤ n ≤ 200\,000)—— 罪犯的数量。

第二行包含三个整数 aa、bb 和 cc(1 ≤ a, b, c ≤ 1081 ≤ a,\,b,\,c ≤ 10^8)—— 三位火枪手的力量值。

第三行包含 nn 个整数 t1, t2, ..., tnt_1,\,t_2,\,...,\,t_n(1 ≤ ti ≤ 1081 ≤ t_i ≤ 10^8)—— 各罪犯的力量值。

输出格式

Print one line with the answer.

If it's impossible to defeat all criminals, print "-1" (without the quotes). Otherwise, print the minimum number of hours the three musketeers will spend on defeating all criminals.

输出一行答案。

如果无法击败所有罪犯,则输出 -1(不带引号)。否则,输出三位火枪手击败所有罪犯所需的最少小时数。

输入输出样例

  • 输入#1

    5
    10 20 30
    1 1 1 1 50

    输出#1

    2
  • 输入#2

    5
    10 20 30
    1 1 1 1 51

    输出#2

    3
  • 输入#3

    7
    30 20 10
    34 19 50 33 88 15 20

    输出#3

    -1
  • 输入#4

    6
    10 5 10
    10 9 5 25 20 5

    输出#4

    3

说明/提示

In the first sample Athos has strength 10, Borthos 20, and Caramis 30. They can defeat all criminals in two hours:

  • Borthos and Caramis should together fight a criminal with strength 50. In the same hour Athos can fight one of four criminals with strength 1.
  • There are three criminals left, each with strength 1. Each musketeer can fight one criminal in the second hour.

In the second sample all three musketeers must together fight a criminal with strength 51. It takes one hour. In the second hour they can fight separately, each with one criminal. In the third hour one criminal is left and any of musketeers can fight him.

在第一个样例中,阿多斯的力量值为 10,波尔多斯为 20,阿拉密斯为 30。他们可在两小时内击败所有罪犯:

  • 波尔多斯与阿拉密斯应合力对抗一名力量值为 50 的罪犯;与此同时,阿多斯在该小时内可单独对抗四名力量值均为 1 的罪犯中的一名。
  • 剩余三名罪犯,每人力量值均为 1;在第二小时内,每位火枪手可各自对抗一名罪犯。

在第二个样例中,三名火枪手必须合力对抗一名力量值为 51 的罪犯,耗时一小时;在第二小时内,他们可各自单独对抗一名罪犯;第三小时内还剩一名罪犯,任一火枪手均可将其击败。

输入解题思路,AI测评打分。不知道怎么写?

首页