(CodeForces

来源:互联网 发布:如何注册网络作家 编辑:程序博客网 时间:2024/06/05 04:43

(CodeForces - 514D)R2D2 and Droid Army

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

题目大意:有n个连续排列的机器人,每个机器人都有m个属性,每个属性不一定相同,现在可以进行k次攻击,每次只能攻击一种属性,每一次攻击可以使所有机器人的该种属性值-1,现要求在不超过k次攻击的情况下,消灭尽可能多的连续机器人序列,输出每种属性的攻击次数。

思路:首先RMQ预处理出每个属性的区间最大值,后面只需要枚举区间左端点,二分区间长度,所需要攻击的次数是m个属性中该区间的最大值之和,如果这个值小于k那么增加区间长度,否则减少区间长度。要注意的是,一个机器人都不能消灭,那么每个属性的攻击次数应该是0,因为要求最少的攻击次数消灭尽可能多的连续机器人。其他细节见代码。

#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int maxn=100005;int a[6][maxn],d[6][maxn][20],le[maxn];int n,m,k;void initRMQ(){    for(int k=1;k<=m;k++)//k代表哪一种属性     {        for(int i=1;i<=n;i++) d[k][i][0]=a[k][i];        for(int j=1;(1<<j)<=n;j++)            for(int i=1;i+(1<<j)-1<=n;i++)//这里小于等于n等号要有                 d[k][i][j]=max(d[k][i][j-1],d[k][i+(1<<(j-1))][j-1]);    }}int RMQ(int k,int l,int r){    int t=0;    while((1<<(t+1))<=r-l+1) t++;//如果2^(k+1)<=r-l+1,那么t还可以加1    return max(d[k][l][t],d[k][r-(1<<t)+1][t]); }bool check(int x)//判断二分的区间长度x{    for(int i=1;i+x-1<=n;i++)//起点    {        int sum=0;        for(int j=1;j<=m;j++) sum+=RMQ(j,i,i+x-1);        if(sum<=k)        {            le[x]=i;//le数组记录区间长度为x的区间左端点             return true;//说明当前区间长度可以,而所求真正的答案比x大         }    }     return false;} int main(){    while(~scanf("%d%d%d",&n,&m,&k))    {        memset(le,0,sizeof(le));        for(int i=1;i<=n;i++)            for(int j=1;j<=m;j++) scanf("%d",&a[j][i]);        initRMQ();        int lo=0,hi=n,mid;        int ans=0;//如果不能消灭,每一项都要输出0         while(lo<=hi)        {            mid=(lo+hi)>>1;            if(check(mid))            {                ans=mid;//记录二分出来的区间长度                 lo=mid+1;            }            else hi=mid-1;        }        for(int i=1;i<=m;i++)         {            if(i==m) printf("%d\n",RMQ(i,le[ans],le[ans]+ans-1));            else printf("%d ",RMQ(i,le[ans],le[ans]+ans-1));        }    }    return 0;}
原创粉丝点击