zoukankan      html  css  js  c++  java
  • Let Them Slide

    E. Let Them Slide
    time limit per test
    4 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given nn arrays that can have different sizes. You also have a table with ww columns and nn rows. The ii-th array is placed horizontally in the ii-th row. You can slide each array within its row as long as it occupies several consecutive cells and lies completely inside the table.

    You need to find the maximum sum of the integers in the jj-th column for each jj from 11 to ww independently.

    Optimal placements for columns 11, 22 and 33 are shown on the pictures from left to right.

    Note that you can exclude any array out of a column provided it remains in the window. In this case its value is considered to be zero.

    Input

    The first line contains two integers nn (1n1061≤n≤106) and ww (1w1061≤w≤106) — the number of arrays and the width of the table.

    Each of the next nn lines consists of an integer lili (1liw1≤li≤w), the length of the ii-th array, followed by lili integers ai1,ai2,,ailiai1,ai2,…,aili (109aij109−109≤aij≤109) — the elements of the array.

    The total length of the arrays does no exceed 106106.

    Output

    Print ww integers, the ii-th of them should be the maximum sum for column ii.

    Examples
    input
    Copy
    3 3
    3 2 4 8
    2 2 5
    2 6 3
    
    output
    Copy
    10 15 16 
    
    input
    Copy
    2 2
    2 7 8
    1 -8
    
    output
    Copy
    7 8 
    
    Note

    Illustration for the first example is in the statement.

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    const int maxn = 1e6 + 10000;
    int n, w;
    vector<ll> e[maxn];
    ll tag[maxn], tot[maxn];
    
    int main() {
        //freopen("1.txt", "r", stdin);
        scanf("%d%d", &n, &w);
        for (register int i = 1, l; i <= n; ++i) {
            scanf("%d", &l);
            //e[i].resize(l + 100);
            e[i].emplace_back(0);
            ll x;
            for (register int j = 1; j <= l; ++j) {
                scanf("%lld", &x);
                e[i].emplace_back(x);
            }
            ll mx = max(*max_element(e[i].begin(), e[i].end()), 1ll * 0);
            //printf("debug mx = %d
    ", mx);
            if (2 * l <= w) {
                ll head_max = 0;
                for (register int j = 1; j <= l; ++j) {
                    head_max = max(head_max, e[i][j]);
                    tot[j] += head_max;
                }
                ll tail_max = 0;
                for (register int j = l, cur = w; j >= 1; --j, --cur) {
                    tail_max = max(tail_max, e[i][j]);
                    tot[cur] += tail_max;
                }
                tag[l + 1] += mx;
                tag[w - l + 1] -= mx;
            } else {
                multiset<ll> cap;
                for (register int j = 1, k = 1; j <= w; ++j) {
                    if (j <= l)cap.insert(e[i][j]);
                    ll cur_max = *cap.rbegin();
                    if (j > l || j < w - l + 1)cur_max = max(cur_max, 1ll * 0);
                    tot[j] += cur_max;
                    //printf("debug k = %d
    ",k);
                    if (j - k + 1 == w - l + 1) {
                        //printf("debug tot[%d] = %d
    ",j,tot[j]);
                        //if(cap.find(e[i][k])!=cap.end()){
                        cap.erase(cap.find(e[i][k]));
                        ++k;
                        //}
                    }
                }
            }
        }
        ll cur = 0;
        for (register int i = 1; i <= w; ++i) {
            cur += tag[i];
            printf("%lld%c", cur + tot[i], (i == w) ? '
    ' : ' ');
        }
        return 0;
    }
  • 相关阅读:
    debian下使用mplayer
    Linux缺点要挟网银平安 SSL证书遽需改换
    linux用C如何鉴别一个目录能否为空
    Ubuntu旗舰版(Ultimate)1.8
    Linux系统下IP以及DNS设置方法
    升级firefox 3.0 beta 到RC1
    微星下月推Wind超低价NB 可运转XP和Linux
    Linux下hosts、host.conf、resolv.conf的区别
    传华硕将在6月3日闪现EBox台式电脑
    linux批改ssh端口和避免root远程上岸设置
  • 原文地址:https://www.cnblogs.com/czy-power/p/11410798.html
Copyright © 2011-2022 走看看