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

让你求最大长度:非常自然想到二分方法,然而还要推断二分到此长度的方案可不可行。

就要找到区间最大值(二维RMQ),RMQ对于查询来说很方便。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
typedef long long LL;
typedef pair<int,int>pil;
const int INF = 0x3f3f3f3f;
const int maxn=1e5+10;
int n,m,kk;
int dp[10][maxn][20];//第j种特性
int num[maxn][10];
int res[10],ans[10];
void init()
{
REPF(i,1,n)
REPF(j,1,m)//多个
dp[j][i][0]=num[i][j];
for(int k=1;k<=m;k++)
for(int j=1;(1<<j)<=n;j++)
for(int i=1;i+(1<<j)-1<=n;i++)
dp[k][i][j]=max(dp[k][i][j-1],dp[k][i+(1<<(j-1))][j-1]);
}
int RMQ(int id,int l,int r)
{
int k=(int)(log(r-l+1)/log(2.0));
return max(dp[id][l][k],dp[id][r-(1<<k)+1][k]);
}
bool ok(int x)
{
for(int i=1;i+x-1<=n;i++)
{
int sum=0;
for(int j=1;j<=m;j++)
{
res[j]=RMQ(j,i,i+x-1);
sum+=res[j];
}
if(sum<=kk)
{
REPF(j,1,m) ans[j]=res[j];
return true;
}
}
return false;
}
void BS()
{
int l=0,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(ok(mid)) l=mid+1;
else r=mid-1;
}
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&kk))
{
REPF(i,1,n)
REPF(j,1,m) scanf("%d",&num[i][j]);
init();BS();
REPF(i,1,m) printf("%d ",ans[i]);
puts("");
}
return 0;
}

Codeforces 514 D R2D2 and Droid Army(RMQ+二分法)的更多相关文章

  1. Codeforces 514 D R2D2 and Droid Army(Trie树)

    题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...

  2. 【codeforces 514D】R2D2 and Droid Army

    [题目链接]:http://codeforces.com/contest/514/problem/D [题意] 给你每个机器人的m种属性p1..pm 然后r2d2每次可以选择m种属性中的一种,进行一次 ...

  3. Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]

    传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. R2D2 and Droid Army(多棵线段树)

    R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 【Cf #291 B】R2D2 and Droid Army(二分,线段树)

    因为题目中要求使连续死亡的机器人最多,令人联想到二分答案. 考虑如何检验这之中是否存在一段连续的长度为md的区间,其中花最多k步使得它们都死亡. 这个条件等价于区间中m个最大值的和不超过k. 枚举起点 ...

  6. [Codeforces #514] Tutorial

    Link: Codeforces #514 传送门 很简单的一场比赛打崩了也是菜得令人无话可说…… D: 一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可 此题 ...

  7. codeforces#514 Div2---1059ABCD

    1059A---Cashier http://codeforces.com/contest/1059/problem/A 题意: Vasya每天工作\(l\)个小时,每天服务\(n\)个顾客,每个休息 ...

  8. School Personal Contest #1 (Codeforces Beta Round #38)---A. Army

    Army time limit per test 2 seconds memory limit per test 256 megabytes input standard input output s ...

  9. Codeforces 1175F The Number of Subpermutations (思维+rmq)

    题意: 求区间[l, r]是一个1~r-l+1的排列的区间个数 n<=3e5 思路: 如果[l,r]是一个排列,首先这里面的数应该各不相同,然后max(l,r)应该等于r-l+1,这就能唯一确定 ...

随机推荐

  1. Google jsAPI托管你的js库

    来看一段JS: <script type="text/javascript" src="http://www.google.com/jsapi">& ...

  2. Phone Number 2010年山东省第一届ACM大学生程序设计竞赛

    Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...

  3. 在CentOS下安装配置MySQL(转)

    今天刚把项目做完,需要马上部署到新到的测试服务器上,于是乎,要在服务器上安装环境,由于好久在linux上部署了,手有些生,比较费劲装完,现在把重要步骤贴出,供自己以后参照.1.首先要看看有没有已经安装 ...

  4. mtk硬件项目开始关闭蓝牙功能:mtk 硬件ScanCode和keycode应用演示示例

    项目要求:该项目因为没有使用android5.0,导致启动bluetooth的蓝牙audio slave功能必须使用第三方模组,该第三方模组,启动是通过android主板通过GPIO控制.UI界面是通 ...

  5. MFC调试小技巧

    今天看acl源码的时候看到一个函数AllocConsole().百度一下感觉这个函数对于调试非常不错,当然对于MFC里面的调试信息,我都是用TRACE打印自己感兴趣的消息的,而且仅仅有在DEBUG里面 ...

  6. 使用dfs实现1至n全阵列

    使用dfs实现1至n全阵列. 我的方法是从所述第一位置开始,使用dfs看上去就像每个头号位置, 当某个位置.从小到大枚举1至n所有号码,打假说 尚未使用之前在这个位置上的几个选择这个号码.然后搜索下 ...

  7. 全新E:网站不是之前排名浮动 相比于竞争对手究竟缺少了什么?

    这几天有非常多朋友问新辰,为什么站点排名掉了?为什么被人家逆袭反超了?当然,这无疑与你站点的内容.外链和用户体验有非常大关系,只是.新辰在此觉得,还须要多研究一下竞争对手的站点,做到:人无我有.人有我 ...

  8. HR筒子说:程序猿面试那点事

    小屁孩曾经有过4年的招聘经验,期间见识了各种类型的程序猿:有大牛.有菜牛:有功成名就,有苦苦挣扎不知方向.等后来做了一枚程序猿之后发现,HR眼中的程序猿和程序猿中的HR都是不一样的.有感与此,从HR的 ...

  9. Android下拉刷新上拉载入控件,对全部View通用!

    转载请声明出处http://blog.csdn.net/zhongkejingwang/article/details/38868463 前面写过一篇关于下拉刷新控件的博客下拉刷新控件终结者:Pull ...

  10. GitLab 之 Linux十分钟快装(转)

    先把 Shell 命令贴出来,楼主以 CentOS release 6.5 (Final) 64位 为例: //配置系统防火墙,把HTTP和SSH端口开放. sudo yum install curl ...