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

Source: Internet
Author: User

Codeforces Round #291 (Div. 2) --- 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, clerk a2, clerk ,..., When am, where ai is the number of details of the I-th type in this droid's mechanisms. 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 shocould R2-D2 make to destroy the sequence of consecutive droids of maximum length?
Input

The first line contains three integers n, middle m, middle k (1 branch ≤ upper n branch ≤ lower 105, 1 branch ≤ lower m branch ≤ lower 5, 0 rows ≤ limit k rows ≤ limit 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, comment a2, comment ,..., When am (0 rows ≤ artificial ai blocks ≤ average 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 shocould 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.

Water question, second answer, and then enumerate the maximum range of the start point query, use RMQ

/*************************************** * *********************************> File Name: cf-291-d.cpp> Author: ALex> Mail: zchao1995@gmail.com> Created Time: ******************************** **************************************** /# include <map> # include <set> # include <queue> # include <stack> # include <vector> # include <cmath> # include <cstdio> # include <cstdlib> # include <cstr Ing >#include <iostream >#include <algorithm> using namespace std; const double pi = acos (-1); const int inf = 0x3f3f3f; const double eps = 1e-15; typedef long LL; typedef pair <int, int> PLL; const int N = 100010; int dp [6] [N] [20]; int arr [N] [6]; int ans [6]; int ret [6]; int LOG [N]; void initRMQ (int n, int m) {for (int k = 1; k <= m; ++ k) {for (int I = 1; I <= n; ++ I) {dp [k] [I] [0] = arr [I] [k];} for (I Nt j = 1; j <= LOG [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 ST (int t, int l, int r) {int k = LOG [r-l + 1]; return max (dp [t] [l] [k], dp [t] [r-(1 <k) + 1] [k]);} int main () {int n, m; LL k; LOG [0] =-1; for (int I = 1; I <= N; ++ I) {LOG [I] = (I & (I-1 )) = 0 )? LOG [I-1] + 1: LOG [I-1];} while (~ Scanf ("% d % lld", & n, & m, & k) {for (int I = 1; I <= n; ++ I) {for (int j = 1; j <= m; ++ j) {scanf ("% d", & arr [I] [j]) ;}} initRMQ (n, m); int l = 1, r = n; int mid; memset (ans, 0, sizeof (ans); memset (ret, 0, sizeof (ret); while (l <= r) {bool flag = false; mid = (l + r)> 1; for (int I = 1; I <= n-mid + 1; ++ I) {LL sum = 0; for (int j = 1; j <= m; ++ j) {int tmp = ST (j, I, I + mid-1); sum + = tmp; ret [j] = tmp;} if (sum> k) {memset (ret, 0, sizeof (ret); continue;} flag = true; break;} if (flag) {for (int I = 1; I <= m; ++ I) {ans [I] = ret [I];} l = mid + 1;} else {r = mid-1 ;}} printf ("% d ", ans [1]); for (int I = 2; I <= m; ++ I) {printf ("% d", ans [I]);} printf ("\ n");} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.