CF888E.Maximum Subsequence

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn integers, and additionally an integer mm . You have to choose some sequence of indices b1,b2,...,bkb_{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 .

输入格式

The first line contains two integers nn and mm ( 1<=n<=351<=n<=35 , 1<=m<=1091<=m<=10^{9} ).

The second line contains nn integers a1a_{1} , a2a_{2} , ..., ana_{n} ( 1<=ai<=1091<=a_{i}<=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,2b={1,2} , so the sum is equal to 77 (and that's 33 after taking it modulo 44 ).

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

首页