Help in this problem

Peter Parker is given a matrix a of size N x M. Each cell inside the matrix is made up of random number of candies. Where the number of candies are in the range 1 to 70.

He can choose no more than C cells in each row. Peter having great power, has great responsibility and is hence not available. You were told by Peter to choose atmost C cells from each row and make the sum of count of candies a multiple of P and maximum as possible.

Note Peter only wants the sum of candies to be a multiple of P. He is totally fine if you choose no such cell with any amount of candies.

Input Format

First line of input consists of and N, M, C, P.

The next N lines contain M elements separated by spaces.

Constraints
1 <= N,M,C,P <=70

Sample Input 0

3 4 2 3
1 1 3 1
9 2 1 1
7 5 1 2

Sample Output 0

27

@ssjgz @carre

There is a similar problem here: https://codeforces.com/contest/1433/problem/F
with edital: https://codeforces.com/blog/entry/83903.

1 Like