C - R2D2 and Droid Army(rmq+二分)

题面:

 

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.

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项属性,每个机器人的每项属性并不统一。要消灭一个机器人,需要将他的每项属性值都减为1,现在有k次操作机会,每次操作可以将每个机器人的某项属性值都减1,问在不超过k次操作的情况下,如何分配每项属性减几次,可以使得最终消灭最多的连续机器人序列,输出分配攻击方案。

     注意:如果不能全部消灭,则每项输出0,因为要求消耗尽量少的操作数,达到杀死尽量多连续的机器人。

解题:

     RMQ,区间询问问题,可以做到O(nlogn)复杂度预处理,O(log n)复杂度询问,入门ST算法,可以看这篇博客,通过RMQ预处理好每项属性,区间最大值。

     随后询问时,只要查询出该区间每项属性的最大值,随后将这些最大值累加,即为消灭该区间全部机器人的最小操作次数。

     枚举左端点,二分右区间,若区间需要操作数大于k,则左移右区间,缩小区间长度,若小于等于k则,右移右区间,增大区间长度。在二分过程中更新区间最优值,同时还需记录此时的分配情况,若区间长度相等的情况下,还需保证操作数尽量小。

由此可以得出rmq算法还可以分别处理二维数组每个列的最大值,nlogn处理,logn查询

 

#include<iostream>
#include<cstring>
#include<stdio.h>
const int maxn=100005;
const int maxlog=20;
using namespace std;

int n,m,k;
int a[100005][6];
int path[6];//最终每条路的操作步骤
int tmp[6];//中间每条路的操作步骤
struct RMQ //用于求区间最值  (传入的是二维数组)
{
    int d[maxn][6][maxlog];
    void init(  int A[][6],int n) //被求最值的数组,数组的大小
    {
        //int n = A.size();
        for(int i = 1; i <= n; i++)
            for(int j=1;j<=m;j++)
                d[i][j][0]=A[i][j];
        for(int j = 1; (1<<j) <= n; j++)
            for(int i = 1; i + (1<<j) - 1 <= n; i++)
                for(int k=1;k<=m;k++)
                    d[i][k][j] = max(d[i][k][j-1], d[i + (1<<(j-1))][k][j-1]);
    }
    int query(int L, int R)
    {
        int res=0;
        if(R < L) swap(L, R);
        //L++;
        for(int i=1;i<=m;i++)
        {
            int k = 0;
            while((1<<(k+1)) <= R-L+1) k++; // 如果2^(k+1)<=R-L+1,那么k还可以加1
            tmp[i]=max(d[L][i][k], d[R-(1<<k)+1][i][k]);
            res+=tmp[i];
        }
        return res;
    }
};
void updata()
{
    for(int j=1;j<=m;j++)
        path[j]=tmp[j];
}
RMQ rmq;
int main()
{
    std::ios::sync_with_stdio(false);
    while(cin>>n>>m>>k)
    {
        int ans=0,ansk=0x3f3f3f3f;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cin>>a[i][j];
            }
        }
        rmq.init( a,n );
        for(int i=1;i<=n;i++)
        {
            int l=i,r=n;
            while(l<=r)
            {
                int mid=(l+r)>>1;
                int temp=rmq.query(i,mid);
                if(temp <= k) //操作步骤少于k
                {
                    if(mid-i+1 > ans)//如果消灭机器人更多
                    {
                        ansk= temp;
                        ans= mid-i+1;
                        updata();
                    }
                    else if(mid-i+1 == ans)//如果消灭一样多
                    {
                        if(ansk>temp)//步骤更少
                        {
                            ansk=temp;
                            updata();
                        }
                    }
                    l=mid+1;
                }
                else
                {
                    r=mid-1;
                    if(r-i+1 <ans)
                        break;
                }
            }
        }
        printf("%d",path[1]);
        for(int i=2;i<=m;i++)
            printf(" %d",path[i]);
        printf("\n");

    }


}

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园的建设目标是通过数据整合、全面共享,实现校园内教学、科研、管理、服务流程的数字化、信息化、智能化和多媒体化,以提高资源利用率和管理效率,确保校园安全。 智慧校园的建设思路包括构建统一支撑平台、建立完善管理体系、大数据辅助决策和建设校园智慧环境。通过云架构的数据中心与智慧的学习、办公环境,实现日常教学活动、资源建设情况、学业水平情况的全面统计和分析,为决策提供辅助。此外,智慧校园还涵盖了多媒体教学、智慧录播、电子图书馆、VR教室等多种教学模式,以及校园网络、智慧班牌、校园广播等教务管理功能,旨在提升教学品质和管理水平。 智慧校园的详细方案设计进一步细化了教学、教务、安防和运维等多个方面的应用。例如,在智慧教学领域,通过多媒体教学、智慧录播、电子图书馆等技术,实现教学资源的共享和教学模式的创新。在智慧教务方面,校园网络、考场监控、智慧班牌等系统为校园管理提供了便捷和高效。智慧安防系统包括视频监控、一键报警、阳光厨房等,确保校园安全。智慧运维则通过综合管理平台、设备管理、能效管理和资产管理,实现校园设施的智能化管理。 智慧校园的优势和价值体现在个性化互动的智慧教学、协同高效的校园管理、无处不在的校园学习、全面感知的校园环境和轻松便捷的校园生活等方面。通过智慧校园的建设,可以促进教育资源的均衡化,提高教育质量和管理效率,同时保障校园安全和提升师生的学习体验。 总之,智慧校园解决方案通过整合现代信息技术,如云计算、大数据、物联网和人工智能,为教育行业带来了革命性的变革。它不仅提高了教育的质量和效率,还为师生创造了一个更加安全、便捷和富有智慧的学习与生活环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值