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. swift-自定义无限轮播图

    一  前言 1.之前一直在用OC编程,最近才开始接触使用swift就发现使用OC越来越不习惯,感觉已经爱上了swift. 2.这个自定义轮播图只是对之前OC版本进行了翻译,欢迎指正. 3.我决定一步步 ...

  2. MVC5 属性路由

    属性路由(attribute routing)是最新被引进到MVC5中的,它和传统路由共同组成了mvc5中的两种主要路由. 1. 高质量的url应该满足以下几点 域名便于记忆和拼写 简短 便于输入 可 ...

  3. id,class,name区别

    id,class,name区别 id:标签唯一标识,好比我们身份证号码,具有唯一性.JS常用document,getGlementBy(id). class:标签的类别,可重复使用,CSS常用. na ...

  4. THREE.js代码备份——canvas - lines - colors(希尔伯特曲线3D、用HSL设置线颜色)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - l ...

  5. windows phone 8 开发系列(二)Hello Wp8!

    上篇我们了解了WP8的环境搭建,从今天开始,我们就正式进入WP8的设计,开发阶段. 一. 项目模板介绍 打开vs,选择Windows Phone的项目模板,我们发现如下有很多模板,那么我们就从认识这些 ...

  6. zynq 之u-boot

    u-boot 启动文件分析 u-boot首先执行的文件:C:\Users\summer_spinach\Desktop\zynq_linux相关\linux\uboot内核\u-boot-xarm\a ...

  7. Android 悬浮窗 WindowManager WindowManager.LayoutParamas

    前方高清大图~~~~ 绘制的图片资源: // draw bitmap BitmapDrawable bmpDraw = (BitmapDrawable) getResources().getDrawa ...

  8. 批处理测试局域网网络连通性ping1-255

    for /l %%1 in (1 1 255)do ping /n 1 192.168.1.%%1       ##bat下 运行 for /l %i in (1,1,254) do ping -n ...

  9. Java抽象类和抽象方法例子

    题目:定义Shape类表示一般二维图形.Shape具有抽象方法area和perimeter,分别计算形状的面积和周长.试定义一些二维形状类(如矩形.三角形.圆形等),这些均为Shape类的子类并计算出 ...

  10. C#定时器和事件

    C#定时器和事件 System.Timers.Timer myTimer; private void Form1_Load(object sender, EventArgs e) { myTimer ...