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-KVC和KVO精炼讲解(干货)

    一.KVO介绍 KVO就是观察者模式,说白了就是你关心的一个值改变了,你就会得到通知.你就可以在你想处理的地方处理这个值. 二.KVO的使用 一般分为三步: 注册监听 使用方法: /** * 添加KV ...

  2. iOS-RunLoop,为手机省电,节省CPU资源,程序离不开的机制

    RunLoop是什么?基本操作是什么? 1.RunLoop的作用 RunLoop可以: 保持程序的持续运行 处理App中的各种事件(比如触摸事件.定时器事件.Selector事件) 节省CPU资源,提 ...

  3. C语言知识总结(2)

    选择结构-if if(表达式) {} {}为作用域 多重if-else  例如: #include <stdio.h> int main(){ ; ){ printf("没有购物 ...

  4. dicom格式文件 界定标识符的处理

    转自:http://www.cnblogs.com/assassinx/archive/2013/05/18/3084854.html 说到底无非几个事情 :1传输语法确定 2数据元素读取 3 7fe ...

  5. 20141201--测试 jQuery

    测试 JavaScript 框架库 - jQuery jQuery 是一个 JavaScript 库. 引用 jQuery <!DOCTYPE html> <html> < ...

  6. tcp 和 udp 缓冲区的默认大小及设置【转】

    1. tcp 收发缓冲区默认值 [root@ www.linuxidc.com]# cat /proc/sys/net/ipv4/tcp_rmem   4096    87380   4161536 ...

  7. 8个超炫酷的纯CSS3动画及源码分享

    在现代网页中,我们已经越来越习惯使用大量的CSS3元素,而现在的浏览器也基本都支持CSS3,所以很多时候我们不妨思考一下是否可以用纯CSS3制作一些有趣或者实用的网页.本文要分享8个超炫酷的纯CSS3 ...

  8. 暑假集训(4)第五弹——— 数论(hdu1222)

    题意概括:那天以后,你好说歹说,都快炼成三寸不烂之舍之际,小A总算不在摆着死人脸,鼓着死鱼眼.有了点恢复的征兆.可孟子这家伙说的话还是有点道理,那什么天将降....额,总之,由于贤者法阵未完成,而小A ...

  9. Mac系统Finder访问资源库文件夹

    Mac在Lion版本之后,默认隐藏了“资源库”文件夹,如果有时我们又需要访问它,该怎么办呢? 方法一 打开“Finder”,打开“前往”菜单时按住“Option”键. 方法二 我们也可设置Finder ...

  10. align=absMiddle属性设置

    AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐.AbsMiddle 图像的中间与同一行中最大元素的中间对齐.Baseline 图像的下边缘与第一行文本的下边缘对齐.Bottom 图像的 ...