AT_abc478_b.Topping

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

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.

高桥正在一家拉面店。

这家店有 NN 种配料,其中第 ii 种配料的价格为 ii,带来的幸福感为 WiW_i。

高桥要从中选出三种互不相同的配料,使得它们的总价格不超过 VV。求他所能获得的最大总幸福感。

题目保证:至少存在一种方式,能选出三种互不相同的配料,使其总价格不超过 VV。

输入格式

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

NN VV
W1W_1 W2W_2 …\dots WNW_N

输入从标准输入中按以下格式给出:

NN VV
W1W_1 W2W_2 …\dots WNW_N

输出格式

Output the answer in one line.

一行输出答案。

输入输出样例

  • 输入#1

    5 9
    31 41 59 26 53

    输出#1

    143
  • 输入#2

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

    输出#2

    2095925

说明/提示

Sample 1 Explanation:
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.

Sample 2 Explanation:
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.

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.

样例 1 解释:
选择第 1、第 3 和第 5 种配料时,总价格为 1+3+5=91+3+5=9,总幸福值为 31+59+53=14331+59+53=143。

样例 2 解释:
选择第 2、第 6 和第 7 种配料时,总价格为 2+6+7=152+6+7=15,总幸福值为 448944+670309+976672=2095925448944+670309+976672=2095925。

约束条件

  • 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
  • 所有输入值均为整数。

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

首页