codeforces-scrape

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

747C.md (3112B)


      1 Source: https://codeforces.com/problemset/problem/747/C
      2 
      3 C. Servers
      4 
      5 time limit per test
      6 
      7 2 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 There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
     22 
     23 It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct.
     24 
     25 To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*, *t**i* + 1, ..., *t**i* + *d**i* - 1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored.
     26 
     27 Write the program that determines which tasks will be performed and which will be ignored.
     28 
     29 Input
     30 
     31 The first line contains two positive integers *n* and *q* (1 ≤ *n* ≤ 100, 1 ≤ *q* ≤ 105) — the number of servers and the number of tasks.
     32 
     33 Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1 ≤ *t**i* ≤ 106, 1 ≤ *k**i* ≤ *n*, 1 ≤ *d**i* ≤ 1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
     34 
     35 Output
     36 
     37 Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 4 3  
     45 1 3 2  
     46 2 2 1  
     47 3 4 3
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 6  
     54 -1  
     55 10
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 3 2  
     62 3 2 3  
     63 5 1 2
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 3  
     70 3
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 8 6  
     77 1 3 20  
     78 4 2 1  
     79 6 5 5  
     80 10 1 1  
     81 15 3 6  
     82 21 8 8
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 6  
     89 9  
     90 30  
     91 -1  
     92 15  
     93 36
     94 ```
     95 
     96 Note
     97 
     98 In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
     99 
    100 In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.