Algorithm


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 ≤ 1051 ≤ m ≤ 50 ≤ 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
Copy
5 2 4
4 0
1 2
2 1
0 2
1 3
output
Copy
2 2
input
Copy
3 2 4
1 2
1 3
2 2
output
Copy
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.

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 1e5 + 10;
int n, m, k, a[N][6], sum[N], seg[4 * N][6];

void build(int at, int l, int r) {
	if(l == r) {
		for(int i = 1; i <= m; ++i)
			seg[at][i] = a[l][i];
		return;
	}

	int mid = (l + r) >> 1;
	build(at << 1, l, mid);
	build(at << 1 | 1, mid + 1, r);

	for(int i = 1; i <= m; ++i)
		seg[at][i] = max(seg[at << 1][i], seg[at << 1 | 1][i]);
}

int s, e, tar;
int get(int at, int l, int r) {
	if(l > e || r < s)
		return 0;

	if(l >= s && r <= e)
		return seg[at][tar];

	int mid = (l + r) >> 1;
	return max(get(at << 1, l, mid), get(at << 1 | 1, mid + 1, r));
}

int calc(int l, int r) {
	int sum = 0;
	s = l, e = r;
	for(int i = 1; i <= m; ++i) {
		tar = i;
		sum += get(1, 1, n);
	}
	return sum;
}

int main() {
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j) {
			scanf("%d", &a[i][j]);
			sum[i] += a[i][j];
		}

	build(1, 1, n);

	int l = 1, r = 1, r1, r2, len = 0;
	while(r <= n) {
		while(l < r && calc(l, r) > k)
			++l;

		if(calc(r, l) <= k && r - l + 1 > len)
			len = r - l + 1, r1 = l, r2 = r;;

		++r;
	}

	s = r1, e = r2;
	for(int i = 1; i <= m; ++i) {
		tar = i;
		printf("%s%d", i == 1 ? "" : " ", get(1, 1, n));
	}
	puts("");

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 2 4
4 0
1 2
2 1
0 2
1 3

Output

x
+
cmd
2 2
Advertisements

Demonstration


Codeforces Solution-R2D2 and Droid Army-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+