Codeforces Round 241 (Div. 2)
B
Art Union
Codeforces
1300
原题
← AC →
翻译中…

A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of $*n*$ 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 $*n*$ colors. Adding the $*j*$-th color to the $*i*$-th picture takes the $*j*$-th painter $*t*_{*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 $*j*$-th painter finishes working on the picture, it must go to the $(*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 $*j*$-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.

翻译中…

Input

翻译中…

The first line of the input contains integers $*m*, *n*$ ($1 ≤ *m* ≤ 50000, 1 ≤ *n* ≤ 5$), where $*m*$ is the number of pictures and $*n*$ is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains $*n*$ integers $*t*_{*i*1}, *t*_{*i*2}, ..., *t*_{*in*}$ ($1 ≤ *t*_{*ij*} ≤ 1000$), where $*t*_{*ij*}$ is the time the $*j*$-th painter needs to work on the $*i*$-th picture.

翻译中…

Output

翻译中…

Print the sequence of $*m*$ integers $*r*_{1}, *r*_{2}, ..., *r*_{*m*}$, where $*r*_{*i*}$ is the moment when the $*n*$-th painter stopped working on the $*i*$-th picture.

翻译中…

样例

Input #1
5 1
1
2
3
4
5
Output #1
1 3 6 10 15
InputCopy OutputCopy
Input #2
4 2
2 5
3 1
5 3
10 1
Output #2
7 8 13 21
InputCopy OutputCopy
题目信息
题号
416B
时间限制
1 s
内存限制
256 MB
标签
暴力
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。