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;
    }
  • 相关阅读:
    linux服务器NAT后无法在内网通过外部IP访问内部服务的问题
    Centos7离线部署docker
    centos7运维记录文档
    centos7离线部署Patroni
    nginx常用运维日志分析命令
    Ubuntu只读文件系统修复方法
    pm2常用命令
    Expert 诊断优化系列------------------锁是个大角色
    Expert 诊断优化系列------------------给TempDB 降温
    Expert 诊断优化系列------------------透过等待看系统
  • 原文地址:https://www.cnblogs.com/czy-power/p/11410798.html
Copyright © 2011-2022 走看看