523D.md (2372B)
1 Source: https://codeforces.com/problemset/problem/523/D 2 3 D. Statistics of Recompressing Videos 4 5 time limit per test 6 7 3 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 A social network for dogs called DH (DogHouse) has *k* special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network. 22 23 We know that each server takes one second to recompress a one minute fragment. Thus, any server takes *m* seconds to recompress a *m* minute video. 24 25 We know the time when each of the *n* videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time *s*, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video. 26 27 For each video find the moment it stops being recompressed. 28 29 Input 30 31 The first line of the input contains integers *n* and *k* (1 ≤ *n*, *k* ≤ 5·105) — the number of videos and servers, respectively. 32 33 Next *n* lines contain the descriptions of the videos as pairs of integers *s**i*, *m**i* (1 ≤ *s**i*, *m**i* ≤ 109), where *s**i* is the time in seconds when the *i*-th video appeared and *m**i* is its duration in minutes. It is guaranteed that all the *s**i*'s are distinct and the videos are given in the chronological order of upload, that is in the order of increasing *s**i*. 34 35 Output 36 37 Print *n* numbers *e*1, *e*2, ..., *e**n*, where *e**i* is the time in seconds after the servers start working, when the *i*-th video will be recompressed. 38 39 Examples 40 41 Input 42 43 ``` 44 3 2 45 1 5 46 2 5 47 3 5 48 ``` 49 50 Output 51 52 ``` 53 6 54 7 55 11 56 ``` 57 58 Input 59 60 ``` 61 6 1 62 1 1000000000 63 2 1000000000 64 3 1000000000 65 4 1000000000 66 5 1000000000 67 6 3 68 ``` 69 70 Output 71 72 ``` 73 1000000001 74 2000000001 75 3000000001 76 4000000001 77 5000000001 78 5000000004 79 ```