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. 一次MVVM+ReactiveCocoa实践

    前言 学习MVVM和ReactiveCocoa(简称RAC)也有一段时间了,不过都仅限于看博客,一直对这两个东西很感兴趣,觉得很创新,也一直想找个机会在项目中实践一下,但是还是有一些顾虑,毕竟没有实践 ...

  2. SQL 建表与查询 HTML计算时间差

    create database xue1 go --创建数据库 use xue1 go --引用数据库 create table xinxi ( code int, name ), xuehao ), ...

  3. 采用Service实现本地推送通知

    在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...

  4. BCB6中SCALERICHVIEW加入GIF动画

    记载下,花了不少时间. 1.  项目导入文件GIFImage.pas 来源:http://melander.dk/delphi/gifimage/ 2.  项目导入文件RVGifAnimate.pas ...

  5. iOS Foundation框架 -4.NSDate类的简单用法

    NSDate为日期时间类对象,简单操作: 注意:直接NSLog输出NSDate对象,默认是以0时区为标准,因此会比北京时间少8小时 1.将Date格式转换为自定义格式的字符串格式 // 自定义Date ...

  6. Linux下安装Websphere MB所需的系统rpm包

    很少使用到Linux,这次刚好用户有一个在linux下搭建Websphere MB/MQ的任务.试了几次都不行,经过多方打听,询问原来是少了rpm包的问题,但是,具体包名不详.. --#mount / ...

  7. 杀死进程 kill -9

    cui@bug:~$ killall -h 用法: killall [选项]... [--] 进程名... killall -l, --list killall -V, --version -e,-- ...

  8. svn迁移

    一.       VisualSVN服务器迁移 场景:把A服务器备份到B服务器 方法: 1.拷贝A上Repositories文件夹到B上 2.打开B上VisualSVN Server Manager ...

  9. Linux下ThinkPHP网站目录权限设置

    在windows上运行好好的项目,迁移到Linux上就遇到了很多问题,其中最为重要的是网站目录权限的设置,当然简单期间你可以用 命令 "chmod 777 -R you web site&q ...

  10. 常用ASCII 码对照表

    目前计算机中用得最广泛的字符集及其编码,是由美国国家标准局(ANSI)制定的ASCII码(American Standard Code for Information Interchange,美国标准 ...