33OJ
登录 注册

B. 配料 / Topping

    传统题 1000ms 256MiB

配料 / Topping

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

Takahashi is at a ramen shop.

This shop has NN kinds of toppings, and the ii-th topping has a price of ii and a happiness of WiW_i.

Takahashi chooses three distinct kinds of toppings so that the total price is at most VV. Find the maximum possible total happiness of the toppings he chooses.

The constraints guarantee that there is at least one way to choose three distinct kinds of toppings so that the total price is at most VV.

Constraints

  • 3≤N≤1003 \leq N \leq 100
  • 6≤V≤3N−36 \leq V \leq 3N-3
  • 1≤Wi≤1061 \leq W_i \leq 10^6
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • NN VV
  • W1W_1 W2W_2 …\ldots WNW_N

Output

Output the answer in one line.

5 9
31 41 59 26 53
143

When choosing the first, third, and fifth toppings, the total price is 1+3+5=91+3+5=9, and the total happiness is 31+59+53=14331+59+53=143.

10 16
102228 448944 131224 326172 500169 670309 976672 579051 974511 773940
2095925

When choosing the second, sixth, and seventh toppings, the total price is 2+6+7=152+6+7=15, and the total happiness is 448944+670309+976672=2095925448944+670309+976672=2095925.

ABC478 赛后模拟赛 ✅️

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-10-10 21:40
结束于
2026-10-24 21:40
持续时间
336 小时
主持人
参赛人数
59