日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 514D】R2D2 and Droid Army(二分+滑动窗口ST表,或 尺取+单调队列或STLmultiset)

發布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 514D】R2D2 and Droid Army(二分+滑动窗口ST表,或 尺取+单调队列或STLmultiset) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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?個整數?a1,?a2,?...,?am,其中?ai?是機器人的第?i?項特征值。 R2-D2 想要摧毀盡量多的連續的機器人。 他有?m?種武器, 第?i?種武器可以將所有機器人第?i?項特征值減少1。 (如果該機器人的特征值已經為0,則什么都不發生).

如果一個機器人所有特征值都為0,則認為該機器人被摧毀。R2-D2 可以用?k?次武器。問 R2-D2 最多可以摧毀多少連續的機器人?

Input

第一行包含三個整數?n,?m,?k?(1?≤?n?≤?105,?1?≤?m?≤?5,?0?≤?k?≤?109) — 分別表示機器人數,特征值數和可以動用武器的次數。

之后?n?行每行描述一個機器人。每行包含?m?個整數?a1,?a2,?...,?am?(0?≤?ai?≤?108),其中?ai是這個機器人的第?i?項特征值。

Output

輸出?m?個用空格分開的數,其中第?i?個數表示第?i?種武器使用的次數。

如果有多種方案,輸出任意一種。

可以使用少于?k?次射擊。

解題報告:

先二分,然后check的時候滑動窗口,剛開始是想拿個multiset維護窗口內元素,來尋找最大值,復雜度兩個log,T了,無奈,換成ST表,復雜度降到O(nmlogn),這題也可以直接尺取,復雜度O(nm)

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; ll n,m,k; int a[MAX][6]; int ans[6],tmp[6]; int dp[6][MAX][24],qq[MAX]; void init() {for(int k = 1; k<=m; k++) {for(int i = 1; i<=n; i++) dp[k][i][0] = a[i][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]);}}}for(int i = 1; i<=n; i++) {int k = 0;while(1<<(k+1) <= i) k++;qq[i] = k;} } int cal(int l,int r,int kk) {int k = qq[r-l+1];return max(dp[kk][l][k],dp[kk][r- (1<<k) + 1][k]); } bool ok(int len) {if(len == 0) return 1;ll tt=0;for(int i = 1; i+len-1<=n; i++) {tt=0;for(int j = 1; j<=m; j++) tmp[j] = cal(i,i+len-1,j),tt += tmp[j];if(tt <= k) return 1;} return 0; } int main() {cin>>n>>m>>k;for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {scanf("%d",&a[i][j]);}}init();int l = 0,r = n,mid,ans[6];while(l<=r) {mid = l+r>>1;if(ok(mid)) {for(int i = 1; i<=m; i++) ans[i] = tmp[i];l = mid+1;}else r = mid-1;}for(int i = 1; i<=m; i++) printf("%d ",ans[i]);return 0 ; } /* 1 1 0 0 */

?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的【CodeForces - 514D】R2D2 and Droid Army(二分+滑动窗口ST表,或 尺取+单调队列或STLmultiset)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。