首页 > 其他分享 >Codeforces Round #291 (Div. 2)-D. R2D2 and Droid Army(RMQ)

Codeforces Round #291 (Div. 2)-D. R2D2 and Droid Army(RMQ)

时间:2023-06-12 17:32:25浏览次数:50  
标签:Droid droids int Army number Codeforces destroyed th type


原题链接


D. R2D2 and Droid Army



time limit per test



memory limit per test



input



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



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



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.

用RMQ求区间最大值

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int dp[5][100005][20];
int n, m, k;
int p1[5], p2[5];
void RMQ(int h){
	
	for(int i = 1; (1<<i) <= n; i++){
		for(int j = 0; j+(1<<i) <= n; j++){
			dp[h][j][i] = max(dp[h][j][i-1], dp[h][j+(1<<(i-1))][i-1]);
		}
	}
}
int Query(int l, int r){
	
	int k = 0;
	while(1<<(1+k) <= r - l + 1)
	 k++;
   int ans = 0;
   for(int i = 0; i < m; i++){
   	p2[i]= max(dp[i][l][k], dp[i][r-(1<<k)+1][k]);
   	ans += p2[i];
   } 
   return ans;
}
int main(){
	
//	freopen("in.txt", "r", stdin);
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d", &dp[j][i][0]);
		}
	} 
	for(int i = 0; i < m; i++){
		RMQ(i);
	}
	int l = 0, maxs = 1;
	while(l + maxs <= n){
		int d = Query(l, l+maxs-1);
		if(k >= d){
			memcpy(p1, p2, sizeof(p2));
			maxs++;
		}
		else
		 l++;
	}
    printf("%d", p1[0]);
    for(int i = 1; i < m; i++)
     printf(" %d", p1[i]);
	puts(""); 
	
	return 0;
}





标签:Droid,droids,int,Army,number,Codeforces,destroyed,th,type
From: https://blog.51cto.com/u_16158872/6464286

相关文章

  • Codeforces Beta Round #22 (Div. 2 Only)-D. Segments
    原题链接D.SegmentstimelimitpertestmemorylimitpertestinputoutputYouaregiven nInputThefirstlineoftheinputcontainssingleintegernumber n (1 ≤ n ......
  • Codeforces Round #190 (Div. 2)-C. Ciel and Robot
    原题链接C.CielandRobottimelimitpertestmemorylimitpertestinputoutputs.Eachcharacterof sU':goup,(x,y)  → D':godown,(x,y)  → L':goleft,(x,y)  → R':goright,(x,y) ......
  • Codeforces Round #362 (Div. 2)-D. Puzzles
    原题链接D.PuzzlestimelimitpertestmemorylimitpertestinputoutputBarneylivesincountryUSC(UnitedStatesofCharzeh).USChas n citiesnumberedfrom 1 through......
  • Codeforces Beta Round #29 (Div. 2, Codeforces format)-D. Ant on the Tree
    原题链接D.AntontheTreetimelimitpertestmemorylimitpertestinputoutputConnectedundirectedgraphwithoutcyclesiscalledatree.Treesisaclassofgraphswhic......
  • Android Handler 详解
    概述为了避免多个线程同时更新UI,导致不可预知的错误;所以现今几乎所有的GUI框架都只允许在主线程修改UI;因此这些框架都选择了消息驱动编程模型;消息驱动编程模型有以下几个组件:消息队列:存储待处理的消息分发器:将不同事件分发到不同的业务逻辑单元消息通道:分发器和处理器......
  • kanzi的android程序修改包名和应用程序名字
    1、修改进程名: 2、修改应用程序名字: 3、修改系统调度ID 通知权限 ......
  • scrcpy——Android投屏神器(使用教程)
    scrcpy简介简单地来说,scrcpy就是通过adb调试的方式来将手机屏幕投到电脑上,并可以通过电脑控制您的Android设备。它可以通过USB连接,也可以通过Wifi连接(类似于隔空投屏),而且不需要任何root权限,不需要在手机里安装任何程序。scrcpy同时适用于GNU/Linux,Windows和macOS。它的一些特......
  • Android中实现双缓冲(画板应用)和XML文件定义菜单
    1.什么是双缓冲技术?双缓冲技术就是当用户操作界面完成后,会有一个缓冲区保存用户操作的结果。为什么要使用双缓冲技术?拿Android游戏开发来说,界面贞每次都是全部重画的,也就说画了新的,旧的就没了,所以需要使用双缓冲技术保存之前的内容。如何实现双缓冲?使用一个Bitmap对象保留之前的画......
  • Android自动化随机测试工具-Monkey简介
    Monkey简介Monkey的名字是有何而来的呢?这个没有去怎么考究,Monkey这个工具就是一个调皮的猴子,在App中乱按、乱摸、乱滚、乱跳。Monkey测试是Android平台下自动化测试的一种快速有效的手段,通过Monkey工具可以模拟用户触摸屏幕、滑动轨迹球、按键等操作来对模拟器或者手机设......
  • CodeForces 4B Before an Exam(DP)
    思路:令dp[i][j]为做了i天用了j时间,然后随便转移一下就可以了#include<cstdio>#include<queue>#include<cstring>#include<iostream>#include<cstdlib>#include<algorithm>#include<vector>#include<map>#include<string>#......