#abc251b. B - At Most 3 (Judge ver.)

B - At Most 3 (Judge ver.)

Score : 200200 points

问题描述

设有 NN 个重量,分别称为 Weight 11、Weight 22\dots、Weight NN。其中,Weight ii 的质量为 AiA_i

我们称一个正整数 nn好整数 ,如果满足以下条件:

  • 我们可以选择 最多3个 不同的重量,使得它们的总质量恰好为 nn

请问不大于 WW 的好整数有多少个?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN weights called Weight 11, Weight 22, \dots, Weight NN. Weight ii has a mass of AiA_i.
Let us say a positive integer nn is a good integer if the following condition is satisfied:

  • We can choose at most 33 different weights so that they have a total mass of nn.

How many positive integers less than or equal to WW are good integers?

Constraints

  • 1N3001 \leq N \leq 300
  • 1W1061 \leq W \leq 10^6
  • 1Ai1061 \leq A_i \leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN WW

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

Sample Input 1

2 10
1 3

Sample Output 1

3

If we choose only Weight 11, it has a total mass of 11, so 11 is a good integer.
If we choose only Weight 22, it has a total mass of 33, so 33 is a good integer.
If we choose Weights 11 and 22, they have a total mass of 44, so 44 is a good integer.
No other integer is a good integer. Also, all of 11, 33, and 44 are integers less than or equal to WW. Therefore, the answer is 33.

Sample Input 2

2 1
2 3

Sample Output 2

0

There are no good integers less than or equal to WW.

Sample Input 3

4 12
3 3 3 3

Sample Output 3

3

There are 33 good integers: 3,63, 6, and 99.
For example, if we choose Weights 11, 22, and 33, they have a total mass of 99, so 99 is a good integer.
Note that 1212 is not a good integer.

Sample Input 4

7 251
202 20 5 1 4 2 100

Sample Output 4

48

update @ 2024/3/10 10:42:30