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. P1020 导弹拦截(nlogn求最长不下降子序列)

    题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹 ...

  2. 深入Spring Security-获取认证机制核心原理讲解

    文/朱季谦 本文基于Springboot+Vue+Spring Security框架而写的原创笔记,demo代码参考<Spring Boot+Spring Cloud+Vue+Element项目 ...

  3. vue、react等SPA应用页脚组件闪烁的解决办法

    大家好,我是木瓜太香.大家在开发单页应用的时候,经常会遇到这样的需求,头部和尾部两个组件是大多数组件公用的,而中间的内容区域则是单独存在的,而且一般内容组件逻辑会比较多,如果我们不停刷新页面可能会出现 ...

  4. Salesforce LWC学习(二十四) Array.sort 浅谈

    本篇参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort sal ...

  5. 小程序mpvue中flyio的使用方法

    Fly.js 一个基于Promise的.强大的.支持多种JavaScript运行时的http请求库. 有了它,您可以使用一份http请求代码在浏览器.微信小程序.Weex.Node.React Nat ...

  6. agumaster 分页方案

    本文例程下载:https://files.cnblogs.com/files/xiandedanteng/agumaster20200430-1.zip 之前的分页方案有点小瑕疵,这回修正了一下. 控 ...

  7. python基础 画图

    python 画图 matplotlib 库只保存图片,不显示图片? 在导入库时,添加如下代码 import matplotlib matplotlib.use('Agg')  各种 symbol ? ...

  8. ui自动化---WebDriverApi接口

    一.webdriver client原理 当测试脚本启动Chrome的时候,selenium-webdriver 会首先在新线程中启动Chrome浏览器.启动后selenium-webdriver会将 ...

  9. 《Offer一箩筐》一份高质量「简历」撰写指南,望打扰!!

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」. 如果觉得 「不错」 的朋友,欢迎 「关注 + 留言 + 分享」,文末有完整的获取链接,您的支持是我前进的最大的动力! Hi~ 这里是 ...

  10. time模块:时间戳和格式化好的时间表示方法及互相转换方法

    1.导入time模块   import time 2.获取当前时间的时间戳   time.time() 3.获取当前格式化好的时间   time.strftime(想要获取的格式) 4.时间戳和格式化 ...