CF1433F.Zero Remainder Sum

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a matrix aa of size n×mn \times m consisting of integers.

You can choose no more than ⌊m2⌋\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 kk 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 kk.

Note that you can choose zero elements (and the sum of such set is 00).

给你一个大小为 n×mn \times m 的整数矩阵 aa。

你可以在每一行中至多选择 ⌊m2⌋\left\lfloor\frac{m}{2}\right\rfloor 个元素。你的任务是选择这些元素,使得它们的和能被 kk 整除,并且该和尽可能大。

换句话说,你可以在每一行中至多选择一半(向下取整)的元素,你需要找出满足能被 kk 整除的最大可能元素和。

注意:你可以选择零个元素(此时和为 00)。

输入格式

The first line of the input contains three integers nn, mm and kk (1≤n,m,k≤701 \le n, m, k \le 70) — the number of rows in the matrix, the number of columns in the matrix and the value of kk. The next nn lines contain mm elements each, where the jj-th element of the ii-th row is ai,ja_{i, j} (1≤ai,j≤701 \le a_{i, j} \le 70).

输入的第一行包含三个整数 nn、mm 和 kk(1≤n,m,k≤701 \le n, m, k \le 70),分别表示矩阵的行数、列数以及 kk 的值。接下来的 nn 行每行包含 mm 个元素,其中第 ii 行的第 jj 个元素为 ai,ja_{i, j}(1≤ai,j≤701 \le a_{i, j} \le 70)。

输出格式

Print one integer — the maximum sum divisible by kk you can obtain.

输出一个整数——你能得到的能被 kk 整除的最大和。

输入输出样例

  • 输入#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 22 and 44 in the first row, 55 and 22 in the second row and 77 and 44 in the third row. The total sum is 2+4+5+2+7+4=242 + 4 + 5 + 2 + 7 + 4 = 24.

在第一个例子中,最优解是第一行取 22 和 44,第二行取 55 和 22,第三行取 77 和 44。总和为 2+4+5+2+7+4=242 + 4 + 5 + 2 + 7 + 4 = 24。

输入解题思路,AI测评打分。不知道怎么写?

首页