您的位置:首页 > 其它

codeforces 873 C. Strange Game On Matrix【贪心】

2017-12-01 16:16 423 查看

C. Strange Game On Matrix

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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:

Initially Ivan’s score is 0;

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;

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 n, m 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,还有个k,给 Ivan的初试分数为0,加分策略如下,当每一列的第一个1,往下数k个值(包括这一行),问你这k个值的总和,现在你可以将一些1变成0,问你可以获得的最大分数,例如:样例,可以把第一行第二列的1变成0,这样就可以使得第二列的分数为最大了

分析: 看下范围很小,直接暴力即可,可以维护下前缀和,但这里数据实在太小了,就直接暴力了,cnt数组记录下每列的总和,可以优化下

参考代码

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
using namespace std;

int a[105][105];
int cnt[105];
int main(){
ios_base::sync_with_stdio(0);
int n,m,k;cin>>n>>m>>k;
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= m;j++) {
cin>>a[i][j];
cnt[j] += a[i][j];
}
}
int mi = 0,ma = 0;
for(int j = 1;j <= m;j++) {
if(cnt[j] == 0) continue;
if(cnt[j] == 1) {
ma++;
continue;
}
int s = 0;
int p;
int l = 1;
for(l = 1;l <= n;l++) {
int CNT = 0;
if(a[l][j]) {
for(int i = l;i < l + k && i <= n;i++) {
CNT += a[i][j];
}
if(CNT > s) {
p = l;
s = CNT;
}
}
}
ma += s;
for(int i = 1;i < p;i++) {
mi += a[i][j];
}
}
cout<<ma<<' '<<mi<<endl;
return 0;
}


如有错误或遗漏,请私聊下UP,thx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: