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

來源:互聯網
上載者: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, 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.
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.

水題,二分答案,然後枚舉起點查詢區間最大值,用RMQ即可

/*************************************************************************    > File Name: cf-291-d.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年02月15日 星期日 14時09分50秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long 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 (int 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%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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.