CodeForces - 514D (线段树+二分)

该博客介绍了如何利用线段树和二分查找算法,在限制射击次数k的情况下,找到并摧毁具有最大连续长度的机器人序列。题目中包含n个机器人,每个机器人有m种类型的细节,每种类型细节的数量不同。解决方案是通过维护每个细节类型的最大值,并进行区间判断,确定最佳射击策略。
摘要由CSDN通过智能技术生成

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枪的情况下,我们可以破坏的最长的连续机器人,然后输出我们的方案。

解题思路:我们观察得到m是很小的一个数(m<=5),所以我们可以用一个线段树来维护这m个数,然后我们二分枚举区间来得到这个区间中的每个属性的最大值,然后我们使得这个区间的机器人的所有属性都变为0,就需要开每个属性的最大值的和,判断一下这个值是否小于等于K即可。
但是打排位赛的时候题意读错了,本来一个很简单的二分加线段树,因为我题意都没读懂,就一直没有动手敲。
代码:

#pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#inc
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值