CF416B.Art Union

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of nn painters who decided to organize their work as follows.

Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these nn colors. Adding the jj -th color to the ii -th picture takes the jj -th painter tijt_{ij} units of time.

Order is important everywhere, so the painters' work is ordered by the following rules:

  • Each picture is first painted by the first painter, then by the second one, and so on. That is, after the jj -th painter finishes working on the picture, it must go to the (j+1)(j+1) -th painter (if j<n );
  • each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;
  • each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;
  • as soon as the jj -th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.

Given that the painters start working at time 0, find for each picture the time when it is ready for sale.

输入格式

The first line of the input contains integers m,nm,n ( 1<=m<=50000,1<=n<=51<=m<=50000,1<=n<=5 ), where mm is the number of pictures and nn is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains nn integers ti1,ti2,...,tint_{i1},t_{i2},...,t_{in} ( 1<=tij<=10001<=t_{ij}<=1000 ), where tijt_{ij} is the time the jj -th painter needs to work on the ii -th picture.

输出格式

Print the sequence of mm integers r1,r2,...,rmr_{1},r_{2},...,r_{m} , where rir_{i} is the moment when the nn -th painter stopped working on the ii -th picture.

输入输出样例

  • 输入#1

    5 1
    1
    2
    3
    4
    5
    

    输出#1

    1 3 6 10 15 
  • 输入#2

    4 2
    2 5
    3 1
    5 3
    10 1
    

    输出#2

    7 8 13 21 
首页