QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#22795. Stamps

Estadísticas

You are supplied a set of values for stamps (e.g., {1, 3, 5}) and the maximum number of stamps that can be applied to an envelope (e.g., five stamps). Your goal is to calculate the largest contiguous set of postage that can be accommodated. For the set of {1, 3, 5} with five maximum stamps, one can build:

  1: 1        6: 1+5       11: 5+5+1     16: 5+5+3+3      21: 5+5+5+3+3
  2: 1+1      7: 5+1+1     12: 5+5+1+1   17: 5+5+5+1+1    22: ????
  3: 3        8: 5+3       13: 5+5+3     18: 5+5+5+3
  4: 1+3      9: 5+3+1     14: 5+5+3+1   19: 5+5+5+3+1
  5: 5       10: 5+5       15: 5+5+5     20: 5+5+5+5

There appears to be no way to build 22 cents with no more than five members of this set of stamps. Thus, one can build values in the range $[1,21]$ a total of 21 contiguous stamp values. There is no reason to believe that the largest contiguous set will start with the value 1.

Input

  • Line 1: Two space separated integers, $S$ ($1 \le S \le 20$), the number of stamp types, and $E$ ($1 \le E \le 10$), the maximum number of stamps that can fit on an envelope.
  • Line 2: $S$ different space-separated positive integers representing the values of the stamps ($1 \le \text{stampval} \le 1000$)

Output

The maximum number of contiguous values that can be created by combining the stamps.

Examples

Input 1

3 5
1 3 5

Output 1

21

Problem credits: 1995 ACM Finals

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.