CodeForces - 873C Strange Game On Matrix(暴力+贪心)

题目链接:http://codeforces.com/problemset/problem/873/C

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的矩阵,矩阵中只有0或1两种元素

对于每一列,找出从一个点向下连续的k个点(包含该点),这些点中有几个1,价值就为几。找出最大的价值,一列中只能找一组连续k个点。

数据范围很小,直接贪心+暴力:

遍历每个点,找出最大的价值,刷新一下即可;

ac:

#include<stdio.h>
#include<string.h>  
#include<math.h>  
  
#include<map>   
//#include<set>
#include<deque>  
#include<queue>  
#include<stack>  
#include<bitset> 
#include<string>  
#include<iostream>  
#include<algorithm>  
using namespace std;  

#define ll long long  
#define INF 0x3f3f3f3f  
#define mod 1000000007
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b) 
#define clean(a,b) memset(a,b,sizeof(a))// 水印 
//std::ios::sync_with_stdio(false);


int arr[220][220];

int main()
{
	clean(arr,0);
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
			cin>>arr[i][j];
	}
	int res=0,resf=0;
	for(int i=0;i<m;++i)
	{
		int maxx=0,f=0,can=0;
		for(int j=0;j<n;++j)
		{
			int ans=0;
			for(int z=0;z<k;++z)
				ans=ans+arr[j+z][i];
			if(ans>maxx)//可以被替换 
			{
				f=can;
				maxx=ans;
			}
			can=can+arr[j][i];//替换次数++; 
		}
		res=res+maxx;
		resf=resf+f;
	}
	cout<<res<<" "<<resf<<endl;
	
}

猜你喜欢

转载自blog.csdn.net/qq_40482358/article/details/81450870