J - R2D2 and Droid Army

An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the army by destroying one detail of the i-th type (if the droid doesn't have details of this type, nothing happens to it).

A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at most k shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?

Input

The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively.

Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of details of the i-th type for the respective robot.

Output

Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.

If there are multiple optimal solutions, print any of them.

It is not necessary to make exactly k shots, the number of shots can be less.

Examples

Input

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

Output

2 2

Input

3 2 4
1 2
1 3
2 2

Output

1 3

Note

In the first test the second, third and fourth droids will be destroyed.

In the second test the first and second droids will be destroyed.

#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
 
int n, m, K, a[6][100010];
int dp[6][100010][20];
int ans[100010];
 
void initRMQ()
{
    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
            dp[i][j][0] = a[i][j];
        for(int l = 1; (1 << l) <= n; l++)
            for(int j = 1; (j + (1 << l) - 1) <= n; j++)
                dp[i][j][l] = max(dp[i][j][l - 1], dp[i][j + (1 << (l - 1))][l - 1]);
    }
}
 
int askRMQ(int i, int l, int r)
{
    int k = 0;
    while((1 << (k + 1)) <= r - l + 1) k++;
    return max(dp[i][l][k], dp[i][r - (1 << k) + 1][k]);
}
 
bool check(int mid)//判断mid是否可行
{
    for(int i = 1; i + mid - 1 <= n; i++)//起点
    {
        int need = 0;
        for(int j = 1; j <= m; j++)
            need += askRMQ(j, i, i + mid - 1);
        if(need <= K)
        {
            ans[mid] = i;
            return true;
        }
    }
    return false;
}
 
int main()
{
    memset(ans, 0, sizeof(ans));
    scanf("%d %d %d", &n, &m, &K);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            scanf("%d", &a[j][i]);
    initRMQ();
    int L = 0, R = n, mid, len = 0;
    while(L <= R)
    {
        mid = (L + R) >> 1;
        if(check(mid))
        {
            len = mid;
            L = mid + 1;
        }
        else
            R = mid - 1;
    }
    for(int i = 1; i <= m; i++)
        printf("%d ", askRMQ(i, ans[len], ans[len] + len - 1));
    return 0;
}
171ms 49732kB

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值