传送门

D. 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.

Sample test(s)
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.

题解如标题,线段树+线性扫一遍即可~~~

9855946 2015-02-15 10:16:13 njczy2010 D - R2D2 and Droid Army GNU C++ Accepted 186 ms 27412 KB
9855894 2015-02-15 10:10:30 njczy2010 D - R2D2 and Droid Army GNU C++ Wrong answer on test 6 15 ms 27400 KB
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 100005
#define M 1505
//#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
//#define inf 2147483647
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll n,m,k;
ll ma;
ll ans[]; typedef struct
{
ll t[];
}PP;
PP a[N];
PP tree[*N]; PP build(ll i,ll l,ll r)
{
//printf(" i=%I64d l=%I64d r=%I64d\n",i,l,r);
if(l==r){
tree[i]=a[l];
return tree[i];
}
PP le,ri;
ll mid=(l+r)/;
le=build(*i,l,mid);
ri=build(*i+,mid+,r);
ll j;
for(j=;j<=m;j++){
tree[i].t[j]=max(le.t[j],ri.t[j]);
}
return tree[i];
} PP query(ll i,ll l,ll r,ll L,ll R)
{
//printf(" i=%I64d l=%I64d r=%I64d L=%I64d R=%I64d\n",i,l,r,L,R);
if(l>=L && r<=R) return tree[i];
ll mid;
mid=(l+r)/;
PP le,ri,re;
ll j;
for(j=;j<=m;j++){
le.t[j]=ri.t[j]=;
}
if(mid>=L){
le=query(i*,l,mid,L,R);
}
if(mid<R){
ri=query(i*+,mid+,r,L,R);
}
for(j=;j<=m;j++){
re.t[j]=max(le.t[j],ri.t[j]);
}
return re;
} void ini()
{
memset(ans,,sizeof(ans));
ma=;
ll i,j;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
scanf("%I64d",&a[i].t[j]);
}
}
//printf(" bb\n");
build(,,n);
} void solve()
{
ll st,en;
st=;
en=;
ll now=;
PP re;
ll j;
for(j=;j<=m;j++){
re.t[j]=;
}
while(en<n)
{
en++;
now=;
for(j=;j<=m;j++){
re.t[j]=max(re.t[j],a[en].t[j]);
now+=re.t[j];
}
while(now>k){
st++;
if(st>en){
for(j=;j<=m;j++){
re.t[j]=;
}
break;
}
re=query(,,n,st,en);
now=;
for(j=;j<=m;j++){
now+=re.t[j];
}
//printf(" st=%I64d en=%I64d now=%I64d\n",st,en,now);
}
if(now>k) continue;
// printf(" st=%I64d en=%I64d now=%I64d ma=%I64d\n",st,en,now,ma);
if(en-st+>ma){
ma=en-st+;
for(j=;j<=m;j++){
ans[j]=re.t[j];
}
}
}
} void out()
{
printf("%I64d",ans[]);
ll i;
for(i=;i<=m;i++){
printf(" %I64d",ans[i]);
}
printf("\n");
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
//scanf("%d%d",&n,&m);
while(scanf("%I64d%I64d%I64d",&n,&m,&k)!=EOF)
{
ini();
solve();
out();
}
return ;
}

Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]的更多相关文章

  1. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  2. Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树

    C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...

  3. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  4. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

  5. Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp

    D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...

  6. Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)

    题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...

  7. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心

    B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...

  8. Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)

    题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...

  9. Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP

    题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...

随机推荐

  1. Educational Codeforces Round 12补题 经典题 再次爆零

    发生了好多事情 再加上昨晚教育场的爆零 ..真的烦 题目链接 A题经典题 这个题我一开始推公式wa 其实一看到数据范围 就算遍历也OK 存在的问题进制错误 .. 思路不清晰 两个线段有交叉 并不是端点 ...

  2. Itunes共享机制实现

    http://www.raywenderlich.com/1948/itunes-tutorial-for-ios-how-to-integrate-itunes-file-sharing-with- ...

  3. Ace 在HTML中使用方法

    <!DOCTYPE html> <html> <head> <title>Demo of ACE Editor</title> <!- ...

  4. Jarvis OJ-level3

    使用ret2libc攻击方法绕过数据执行保护 from pwn import* conn = remote("pwn2.jarvisoj.com",9879) elf = ELF( ...

  5. javascript获取属性的两种方法及区别

    javascript获取属性有两种方式,点或者中括号: var obj={} obj.x=1 console.log(obj.x)//1 第一种方式,x是字面量 try{ console.log(ob ...

  6. DOM事件总结

    1.DOM事件: DOM0: element.onclick=function(){} DOM2: element.addEventListener(‘click’,function(){}) add ...

  7. 组合的输出(DFS)

    题目描述: 排列与组合是常用的数学方法,其中组合就是从n个元素中抽出r个元素(不分顺序且r<=n),我们可以简单地将n个元素理解为自然数1,2,…,n,从中任取r个数. 现要求你用递归的方法输出 ...

  8. linux中添加一个用户到指定用户组的两种方式,修改一个用户到指定用户组的一种方式

    添加一个用户到指定用户组: gpasswd –a 用户名 组名usermod –G 组名 用户名 //第一种:gpasswd –a 用户名 组名 [root@localhost ~]# id user ...

  9. Python9-模块2-包的进阶-day21

    包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警觉: ...

  10. timer event

    /* linux/kernel/time/jiffies.c*/ static cycle_t jiffies_read(struct clocksource *cs) { return (cycle ...