Description


Due to its great contribution to the maintenance of world peace, Dzx was given an unlimited amount of candy free coupons to the candy company on May 23, 2010. On this day, Dzx can choose any of the N products from the candy company to take home and enjoy. Each of the N products of the candy company contains a different number of candies. Dzx hopes that the total number of candies in the products he chooses is an integer multiple of K, so that he can evenly distribute the candies to his partners who help him maintain world peace. Of course, on the basis of meeting this condition, the more the total number of candies, the better. How much candy can Dzx take away?
Note: Dzx can only take away the entire product of the candy company.

Format


Input

The first line contains two integers \(N(1 \leq N \leq 100)\) and \(K(1 \leq K \leq 100)\)
The following \(N\) lines have 1 integer in each line, indicating the number of candies contained in the product of the candy company, which does not exceed 1,000,000

Output

The maximum total number of candies that meet the requirements. If it cannot meet the requirement of multiples of \(K\), output 0

Sample


Input

5 7
1
2
3
4
5

Output

14

Sample Explanation

Dzx's choice is \(2+3+4+5=14\), so the total number of candies is a multiple of 7, and it is the most total choice.

Sample Code


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std; int n,k,t;
int f[105][105]; int main() {
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
cin>>n>>k;
for(int i=1; i<=n; i++) {
cin>>t;
f[i][t%k]=t;//Store the total sugar with the same remainder.
for(int j=0; j<k; j++)
if(f[i-1][j])
f[i][(j+t)%k]=f[i-1][j]+t;
for(int j=0; j<k; j++)
f[i][j]=max(f[i][j],f[i-1][j]);
}
cout<<f[n][0]<<endl;//The result with a remainder of 0 is output. If there is no remainder with 0, then output 0 directly.
return 0;
}

Candy (candy)的更多相关文章

  1. Leetcode 动态规划 Candy

    本文senlie原版的,转载请保留此地址:http://blog.csdn.net/zhengsenlie Candy Total Accepted: 16494 Total Submissions: ...

  2. leetcode — candy

    /** * Source : https://oj.leetcode.com/problems/candy/ * * There are N children standing in a line. ...

  3. [LeetCode] Candy 分糖果问题

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  4. Leetcode Candy

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  5. LeetCode 135 Candy(贪心算法)

    135. Candy There are N children standing in a line. Each child is assigned a rating value. You are g ...

  6. [LeetCode][Java]Candy@LeetCode

    Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  7. 【leetcode】Candy(hard) 自己做出来了 但别人的更好

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  8. 【leetcode】Candy

    题目描述: There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  9. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

随机推荐

  1. webpack做项目优化

    webpack优化 -- compression-webpack-plugin 开启gzip 打包的时候开启gzip可以大大减少体积,非常适合于上线部署.下面以vue-cli2.x项目为例,介绍如何在 ...

  2. 13_Python的面向对象编程-类class,对象object,实例instance

    1.面向对象概述 1.类是用来描述对象的工具,把拥有相同属性和行为的对象分为一组     2.对象是由类实例化出来的一个具体的对象         属性: 对象拥有的名词,用变量表示         ...

  3. java实现内网通信

    package newTest; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; ...

  4. js中数组扁平化处理

  5. Navicat 闲置时间过长会卡死

    前段时间使用navicat连接线上的数据库,Navicat 闲置时间过长会卡死.解决方案:选中数据库,右键点击 编辑连接,修改保持连接间隔为 20秒.非常 so easy ! 1. 选中数据库,右键点 ...

  6. Charles的几个用途

    1.拦截请求,篡改请求和响应 拦截请求,修改请求可以测试网站中一些异常的情况,检查服务端是否有校验的情况 检查是否存在漏洞,就看拦截之后修改过的数据是否写进了数据库 使用方法: 举例一:上传文件 1. ...

  7. docker中重启某个服务命令

    docker ps------查看正在运行的cotainners docker ps -a --------查看所有的containners docker restart 容器id docker lo ...

  8. loadrunner做http接口的性能测试

    不用录制脚本的方法 步骤: 1.先打开Virtual User Generator——选择Web/HTTP协议,进入到主页面,这里不按照传统录脚本的方式输入url,所以直接叉掉录制脚本选项,进入下面的 ...

  9. [LeetCode]494. 目标和、416. 分割等和子集(0-1背包,DP)

    题目一 494. 目标和 给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S.现在你有两个符号 + 和 -.对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前 ...

  10. Redis安装即python使用

    一:简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted ...