B. Art Union

time limit per test

                                      1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 tijis 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
5 1
1
2
3
4
5
output
1 3 6 10 15 
input
4 2
2 5
3 1
5 3
10 1
output
7 8 13 21 
题意理解:n幅画m个画家,后一个画家要在前一个画家花了当前那幅画所需部分之后才能画,求每一幅画n个画家画完后所需的时间。
思路:先用b[i][j]存入所输入的数据,然后遍历每一列(第i个画家画完所有画所需时间),用dp[j]存第j幅画完成所需时间。
dp[j]等于前面用的最大时间加上当前他需要的时间。
 #include<bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
int b[n][m];
for(int i=; i<n; i++) {
for(int j=; j<m; j++) {
cin>>b[i][j];
}
}
vector<int> dp(n);
for(int i=;i<m;i++){
int free=;
for(int j=;j<n;j++){
int start=max(free,dp[j]);
dp[j]=start+b[j][i];
free=dp[j];
}
}
for(int i=; i<n; i++)
printf("%d%c",dp[i],i==n-?'\n':' ');
return ;
}


Codeforces Round #241 (Div. 2)->B. Art Union的更多相关文章

  1. 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 ...

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

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

  3. 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 ...

  4. Codeforces Round #241 (Div. 2)->A. Guess a number!

    A. Guess a number! time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces Codeforces Round #484 (Div. 2) D. Shark

    Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D ...

  6. DFS/并查集 Codeforces Round #286 (Div. 2) B - Mr. Kitayuta's Colorful Graph

    题目传送门 /* 题意:两点之间有不同颜色的线连通,问两点间单一颜色连通的路径有几条 DFS:暴力每个颜色,以u走到v为结束标志,累加条数 注意:无向图 */ #include <cstdio& ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. iOS-画板的实现

    先上一张效果图,有看下去的动力 再来一张工程图片 好,首先是对线的实体的封装,在LineEntity.h文件中创建一个点的数组 然后在LineEntity.m文件中,在初始化方法中给points变量开 ...

  2. iOS中关于.pch的新建与配置问题

    以前版本的Xcode新建一个项目都会自动生成.pch,这个文件的好处是,里面添加的东西会自动添加到每个类中,也就是说我们可以把要用的宏定义,和多个头文件等放到.pch中,这样我们就不需要重复的在每个类 ...

  3. 【学习笔记】【C语言】二维数组

    1. 什么是二维数组 一个数组能表示一个班人的年龄,如果想表示很多班呢? 什么是二维数组?int ages[3][10]; 三个班,每个班10个人 相当于3行10列 相当于装着3个一维数组 二维数组是 ...

  4. linux工程管理工具make入门

    一.make工具的功能 1.主要负责一个软件工程中多个源代码的自动编译工作 2.还能进行环境检测.后期处理等工作: 3.make工具可以识别出工程中哪些文件已经被修改,并且在再次编译的时候只编译这些文 ...

  5. JS源码(条件的判定,循环,数组,函数,对象)整理摘录

    --- title: JS学习笔记-从条件判断语句到对象创建 date: 2016-04-28 21:31:13 tags: [javascript,front-end] ---JS学习笔记——整理自 ...

  6. 10款很酷的HTML5动画和实用的HTML5应用

    1.HTML5的画布花朵生成器可生成多种样式的花朵 HTML5非常流行,利用HTML5制作动画也非常方便,今天要分享一款利用HTML5 Canvas制作的花朵生成器,我们只需要在Canvas画布上点击 ...

  7. LLVM language 参考手册 翻译停止相关

    再翻译LLVM language 参考手册的时候,个人感觉很多东西都不是很懂,因此打算学习完编译原理后再去继续研究翻译,多有不便望见谅

  8. JPA SQL 的复杂查询createNamedQuery

    @NamedNativeQueries({ @NamedNativeQuery( name = "getNativeNutShellInfo", //需要调用的name query ...

  9. JavaIO和JavaNIO

    BIO和NIO BIO在之前的服务器处理模型中,在调用ServerSocket.accept()方法时,会一直阻塞到有客户端连接才会返回,每个客户端连接过来后,服务端都会accept一个新连接,接着启 ...

  10. C#的Socket简单实现消息发送

    Socket一般用于网络之间的通信,在这里,实现的是服务端与客户端的简单消息通信.首先是客户端的搭建,一般步骤是先建立Socket绑定本地的IP和端口,并对远端连接进行连接进行监听,这里的监听一般开启 ...