codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

416B.md (2242B)


      1 Source: https://codeforces.com/problemset/problem/416/B
      2 
      3 B. Art Union
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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 *t**ij* units of time.
     24 
     25 Order is important everywhere, so the painters' work is ordered by the following rules:
     26 
     27 * 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*);
     28 * each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;
     29 * each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;
     30 * as soon as the *j*-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.
     31 
     32 Given that the painters start working at time 0, find for each picture the time when it is ready for sale.
     33 
     34 Input
     35 
     36 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 *t**i*1, *t**i*2, ..., *t**in* (1 ≤ *t**ij* ≤ 1000), where *t**ij* is the time the *j*-th painter needs to work on the *i*-th picture.
     37 
     38 Output
     39 
     40 Print the sequence of *m* integers *r*1, *r*2, ..., *r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture.
     41 
     42 Examples
     43 
     44 Input
     45 
     46 ```
     47 5 1  
     48 1  
     49 2  
     50 3  
     51 4  
     52 5
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 1 3 6 10 15
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 4 2  
     65 2 5  
     66 3 1  
     67 5 3  
     68 10 1
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 7 8 13 21
     75 ```