A13774 | Zero Remainder Sum
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a matrix $a$ of size $n \times m$ consisting of integers.
You can choose no more than $\left\lfloor\frac{m}{2}\right\rfloor$ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by $k$ and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by $k$ .
Note that you can choose zero elements (and the sum of such set is $0$ ).
You can choose no more than $\left\lfloor\frac{m}{2}\right\rfloor$ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by $k$ and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by $k$ .
Note that you can choose zero elements (and the sum of such set is $0$ ).
输入格式
The first line of the input contains three integers $n$ , $m$ and $k$ ( $1 \le n, m, k \le 70$ ) — the number of rows in the matrix, the number of columns in the matrix and the value of $k$ . The next $n$ lines contain $m$ elements each, where the $j$ -th element of the $i$ -th row is $a_{i, j}$ ( $1 \le a_{i, j} \le 70$ ).
输出格式
Print one integer — the maximum sum divisible by $k$ you can obtain.
输入输出样例
输入 #1
3 4 3 1 2 3 4 5 2 2 2 7 1 1 4
输出 #1
24
输入 #2
5 5 4 1 2 4 2 1 3 5 1 2 4 1 5 7 1 2 3 8 7 1 2 8 4 7 1 6
输出 #2
56
In the first example, the optimal answer is $2$ and $4$ in the first row, $5$ and $2$ in the second row and $7$ and $4$ in the third row. The total sum is $2 + 4 + 5 + 2 + 7 + 4 = 24$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted