CF888E.Maximum Subsequence

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices _b_1, _b_2, ..., b__k (1 ≤ _b_1 < _b_2 < ... < b__k ≤ n) in such a way that the value of is maximized. Chosen sequence can be empty.

Print the maximum possible value of .

给你一个由 $ n $ 个整数组成的数组 $ a $,以及一个额外的整数 $ m $。你需要选择一个下标序列 $ b_1,,b_2,,\dots,,b_k $(满足 $ 1 \leq b_1 < b_2 < \dots < b_k \leq n $),使得表达式

的值最大化。所选序列可以为空。

请输出该表达式可能取得的最大值:

输入格式

The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).

The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109).

第一行包含两个整数 nn 和 mm(1 ≤ n ≤ 351 \le n \le 35,1 ≤ m ≤ 1091 \le m \le 10^9)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1 ≤ ai ≤ 1091 \le a_i \le 10^9)。

输出格式

Print the maximum possible value of .

输出表达式 的最大可能值。

输入输出样例

  • 输入#1

    4 4
    5 2 4 1

    输出#1

    3
  • 输入#2

    3 20
    199 41 299

    输出#2

    19

说明/提示

In the first example you can choose a sequence b = {1, 2}, so the sum is equal to 7 (and that's 3 after taking it modulo 4).

In the second example you can choose a sequence b = {3}.

在第一个例子中,你可以选择序列 $ b = {1, 2} $,此时和 等于 7(对 4 取模后为 3)。

在第二个例子中,你可以选择序列 $ b = {3} $。

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

首页