Codeforces 873C Strange Game On Matrix【贪心】ʕ •ᴥ•ʔ

C. Strange Game On Matrix

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan is playing a strange game.

He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:

  1. Initially Ivan's score is 0;
  2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped;
  3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score.

Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score.

Input

The first line contains three integer numbers nm and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100).

Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.

Output

Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.

Examples

input

4 3 2
0 1 0
1 0 1
0 1 0
1 1 1

output

4 1

input

3 2 1
1 0
0 1
0 0

output

2 0

Note

In the first example Ivan will replace the element a1, 2.

题目大意:

给出一个N*M的矩阵,我们可以使得矩阵中任意一个1变成0.计算价值的方法是:找到每一列的第一个1,然后计算这个1以及其下边小于等于k的连续段落里边有多少个1,然后加到答案中,现在我们希望使得结果尽可能的大,而且使得变换的次数尽可能的小,输出最大值以及变换的最小次数。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define N 4000000
#define ll long long 
using namespace std;
#define mod 1000000007
int a[105][105];
int main()
{
	int n,m,len;
	while(cin>>n>>m>>len)
	{
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				cin>>a[i][j];
			}
		}
		int ans=0,ans1=0;
		for(int j=0;j<m;j++)
		{
			int sum=0;
			for(int i=0;i<=n-len;i++)
			{
				int  h=0;// 不需要判断是不是为1 
				for(int k=i;k<i+len;k++)
				{
					h+=a[k][j];//记录当前值 
				}
				if(sum<h)//找寻这一列的最大值 
				{
				 	sum=h;
				 	flag=i;//记录这个点 方便寻找其前面点 1 的个数 
				}
			}
			if(sum)//找到这列最大值之后 进行相加 
			{
				ans+=sum;
				for(int i=0;i<flag;i++)
				{
					ans1+=a[i][j];
				}
			}
		}
		printf("%d %d\n",ans,ans1);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/henucm/article/details/81588396