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 tij 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 ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to work on the i-th picture.

Output

Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture.

Examples
input

Copy
  1. 5 1
    1
    2
    3
    4
    5
output

Copy
  1. 1 3 6 10 15
input

Copy
  1. 4 2
    2 5
    3 1
    5 3
    10 1
output

Copy
  1. 7 8 13 21

  1. 做题像是憋屎,想明白后,一下就出来了。
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <set>
  6. #include <queue>
  7. #include <map>
  8. #include <sstream>
  9. #include <cstdio>
  10. #include <cstring>
  11. #include <numeric>
  12. #include <cmath>
  13. #include <unordered_set>
  14. #include <unordered_map>
  15. #include <xfunctional>
  16. #define ll long long
  17. #define mod 998244353
  18. using namespace std;
  19. int dir[][] = { {,},{,-},{-,},{,} };
  20. const int maxn = ;
  21. const long long inf = 0x7f7f7f7f7f7f7f7f;
  22.  
  23. int main()
  24. {
  25. int m, n;
  26. cin >> m >> n;
  27. vector<vector<int>> t(m+, vector<int>(n+,));
  28. for (int i = ; i <= m; i++)
  29. for (int j = ; j <= n; j++)
  30. cin >> t[i][j];
  31. for (int i = ; i <= m; i++)
  32. {
  33. for (int j = ; j <= n; j++)
  34. {
  35. if (t[i][j - ] < t[i - ][j])
  36. t[i][j] += t[i - ][j];
  37. else
  38. t[i][j] += t[i][j - ];
  39. }
  40. }
  41. for (int i = ; i <= m; i++)
  42. {
  43. cout << t[i][n] << " ";
  44. }
  45. return ;
  46. }

Art Union的更多相关文章

  1. Codeforces Round #241 (Div. 2)->B. Art Union

    B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. Codeforces Round #241 (Div. 2) B. Art Union 基础dp

    B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. Codeforces Round #241 (Div. 2) B. Art Union (DP)

    题意:有\(n\)个画家,\(m\)幅画,每个画家负责\(m\)幅画,只有前一个画家画完时,后面一个画家才能接着画,一个画家画完某幅画的任务后,可以开始画下一幅画的任务,问每幅画最后一个任务完成时的时 ...

  4. n个人作m幅画

    题目网址: http://codeforces.com/problemset/problem/416/B A well-known art union called "Kalevich is ...

  5. Codeforces Round #241 (Div. 2) B dp

    B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. The Art of Deception

    前言 一些黑客毁坏别人的文件甚至整个硬盘,他们被称为电脑狂人(crackers)或计算机破坏者(vandals).另一些新手省去学习技术的麻烦,直接下载黑客工具侵入别人的计算机,这些人被称为脚本小子( ...

  7. Android内存优化(一)DVM和ART原理初探

    相关文章 Android内存优化系列 Java虚拟机系列 前言 要学习Android的内存优化,首先要了解Java虚拟机,此前我用了多篇文章来介绍Java虚拟机的知识,就是为了这个系列做铺垫.在And ...

  8. SQL Server-聚焦UNIOL ALL/UNION查询(二十三)

    前言 本节我们来看看有关查询中UNION和UNION ALL的问题,简短的内容,深入的理解,Always to review the basics. 初探UNION和UNION ALL 首先我们过一遍 ...

  9. SQL 提示介绍 hash/merge/concat union

    查询提示一直是个很有争议的东西,因为他影响了sql server 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...

随机推荐

  1. JavaSE学习笔记(13)---线程池、Lambda表达式

    JavaSE学习笔记(13)---线程池.Lambda表达式 1.等待唤醒机制 线程间通信 概念:多个线程在处理同一个资源,但是处理的动作(线程的任务)却不相同. 比如:线程A用来生成包子的,线程B用 ...

  2. idea中创建maven的Javaweb工程并进行配置

    学完maven后,可以创建maven的javaweb工程,在创建完成后还需要一些配置,下面来说下具体步骤,在这里我创建的是一个模块,创建web项目的方式和创建模块一样 1.创建一个模块,点new-Mo ...

  3. python数据类型(总结篇)

    世界上最容易的事是坚持,最难的事也是坚持.开通博客园已两月有余,但实际上笔者本人的活跃度非常低,痛定思痛,自己选的路含泪也要走下去,继续坚持! 本文承接前几个月的python数据类型系列,完成对字典与 ...

  4. 吴裕雄--天生自然 HADOOP大数据分布式处理:安装XShell

    下载安装包

  5. 基于WEB的车票预订信息系统设计

    注册登录界面 用户输入网址以后,用自己的手机号作为账号,然后输入自己想设置的密码注册一个号,然后点击注册,即注册登录.如图5.1所示: 图5.1 车票预订信息系统注册登录界面 5.2  车票查询界面 ...

  6. DFT 问答 I

    Q: Boundary Scan是什么?应用场景是什么?实现的方法是什么?挑战是什么? A: Boundary Scan就是边界扫描,是由Joint Test action Group起草的规范,最初 ...

  7. C# SQLITE 使用文档

    https://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite_namespace.html 有 ...

  8. C# WinForm MessageBox.Show显示在窗体中间

    一.新建MessageBoxEx类,并添加以下代码. using System; using System.Windows.Forms; using System.Text; using System ...

  9. Jackson使用指南

    Jackson常用注解 序列化注解 @JsonAnyGetter 像普通属性一样序列化Map public class ExtendableBean { public String name; pri ...

  10. 886. 求组合数 II(模板)

    数据范围较大, a,b都是1e5 直接根据公式预处理  1/i就是求i的逆元(逆元求法:mod为质数,逆元就是 i^(mod-2)%mod ) O(N*logN) import java.util.S ...