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. 2020年的UWP——通过Radio类控制Cellular(1)

    最近在做UWP的项目,在2020年相信这已经是相对小众的技术了,但是在学习的过程中,发现某软这么几年仍然添加了不少的API,开放了相当多的权限.所以打算总结一下最近的一些经验和收获,介绍一下2020年 ...

  2. 【IDEA】【SpringBoot】基于idea对springboot程序远程调试

    一.开启远程调试前提:本地代码与服务器代码一致(实测:不关键的代码稍微有点不一样好像也不会有多大问题). 二.开启远程调试步骤 1.开发工具配置 idea端打开Edit configurations, ...

  3. Zabbix Server宕机报“__zbx_mem_malloc(): out of memory (requested 96 bytes)”

    早上登录Zabbix的时候,发现其提示"Zabbix server is not running: the information displayed may not be current& ...

  4. Java程序取MySQL的datetime字段,如何消除时间尾后讨厌的".0"

    Problem: 直接取datetime字段的内容会有".0"后缀,如2020-05-03 18:21:39.0,虽无伤大雅但总觉得有些别扭. Solution:使用转化函数Dat ...

  5. 查看CentOs6.5/7的系统版本号

    在centos6.5上用 [root@msg45 ~]# lsb_release -aLSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0- ...

  6. 仿VISIO连线

    说明: 1.未实现障碍物自动避让功能: 2.未实现添加图元到连线之间,连线自动避开新增图元功能: 后续再完善... version 1: package com.sunsheen.jfids.stud ...

  7. 操作DOM对象

    操作DOM对象 目录 操作DOM对象 1. 核心 2. 获得Dom节点 3. 更新节点 1. 操作文本 2. 操作CSS 4. 删除节点 5. 插入节点 1. 追加(将已存在的节点移到后面) 2. 创 ...

  8. node.js之koa安装

    默认安装了node 1.cmd中工作目录下输入npm init:一路回车即可: 2.还是在此目录下输入npm i koa:我这里是安装的淘宝镜像即是输入cpm i koa. 3.打开编辑器在文件目录下 ...

  9. 认证授权:IdentityServer4 - 各种授权模式应用

    前言: 前面介绍了IdentityServer4 的简单应用,本篇将继续讲解IdentityServer4 的各种授权模式使用示例 授权模式: 环境准备 a)调整项目结构如下:   b)调整cz.Id ...

  10. nmap端口扫描工具下载和安装使用

    1.下载地址 https://nmap.org/download.html 2.下载之后进行安装 选择I Agree 后,建议全选,特别是zenmap,这个是图形化界面,不喜欢命令行格式的可以用zen ...