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

Copy

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

output

Copy

4 1

input

Copy

3 2 1
1 0
0 1
0 0

output

Copy

2 0

Note

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

题意什么的代码里注释的很清楚了,

。。。下图。选择性观看,,,(自己能看懂系列。)

(os:这图调了几次。。怎么还是这么大。。。) 

代码:

 

/*
 Strange Game On Matrix
 给出一个n行m列的01矩阵,你可以选矩阵中的几个1把它改成0,
 操作完之后,对于每一列他会找到最上面的一个1(包含),每一列算出当前位置向下len个长度的1的个数有多少,记一个maxx,
 然后一共m列加起来就是他最终的分数。
 对每一列我们求出这一列最多的一出现在哪里,然后将他前面的1都给消去。
 问你最后可以拿到的最大分和最少把几个1改成0。
 如果列中没有 1 将跳过。
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <deque>
using namespace std;
#define N 101
int n,m,k;
int sum[N][N],mapp[N][N];
int main()
{
    int len,res1=0,res2=0;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>mapp[i][j];
            sum[i][j]=mapp[i][j];
        }
    }
    for(int i=1;i<=m;i++)//列   第i列。。。第j行
    {
        for(int j=1;j<=n;j++)//行
        {
            sum[j][i]+=sum[j-1][i];//可以理解为前缀和(1的和)。
        }
    }
    for(int i=1;i<=m;i++)//列
    {
        int cnt=-1,ans=0,maxx=0;
        for(int j=1;j<=n;j++)//行
        {
            if(mapp[j][i]==1)
            {
                len=min(k,n-j+1);
                cnt++;//刚开始遇到cnt加到0. 因为前面没有需要改变的,所以。cnt初始化为-1;
                int tt=sum[j+len-1][i]-sum[j][i]+1;//距离中1的和。
                if(tt>maxx) maxx=tt,ans=cnt;
            }
        }
        res1+=maxx;
        res2+=ans;
    }
    cout<<res1<<" "<<res2<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值