【CF edu 30 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 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.

 

【翻译】给出01矩阵,要求删除1的点(可以不删),使得得分最大。得分计算方式:得分为每列的得分和,每列的得分计算方式为:从上往下第一个为1的位置向下的k长度区间内1的个数即分数(包括这个位置本身)。输出最高分数以及达成这个分数的最小删除数。

 

题解:
      ①贪心。

      ②每一列用单调性维护取最值就是了。

#include<stdio.h>
#include<algorithm>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
using namespace std;const int N=102;
int n,m,k,G[N][N],sum[N],score,ans;
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    go(i,1,n)go(j,1,m)scanf("%d",&G[i][j]);
    go(j,1,m)
    {
        int p,val=0;
        ro(t,n,1)sum[t]=sum[t+1]+G[t][j];
        ro(t,n,1)if(G[t][j]&&sum[t]-sum[min(t+k,n+1)]>=val)
        val=sum[t]-sum[min(t+k,n+1)],p=t;ans+=sum[1]-sum[p];score+=val;
    }
    printf("%d %d\n",score,ans);return 0;
}//Paul_Guderian

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

.

转载于:https://www.cnblogs.com/Damitu/p/7745340.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值