Codeforces Round #387 (Div. 2) C && coedeforces 744 C Servers(水题)
来源:互联网 发布:gps端口查看器 编辑:程序博客网 时间:2024/06/12 00:55
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.
It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.
To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.
Write the program that determines which tasks will be performed and which will be ignored.
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.
Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n,1 ≤ di ≤ 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.
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.
4 31 3 22 2 13 4 3
6-110
3 23 2 35 1 2
33
8 61 3 204 2 16 5 510 1 115 3 621 8 8
6930-11536
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 4will 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).
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.
注意在更改前,先看看能不能符合条件,不符合条件,不能更改,,,还是写代码的时候,脑袋不清晰。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5+5;int t[maxn], k[maxn], d[maxn], book[maxn];int main(){ int n, q; while(cin >> n >> q) { memset(book, 0, sizeof(book)); for(int i = 1; i <= q; i++) cin >> t[i] >> k[i] >> d[i]; for(int i = 1; i <= q; i++) { int cnt = 0, flag = 0, ans = 0; for(int j = 1; j <= n; j++) { if(t[i] > book[j]) cnt++; if(cnt == k[i]) { flag = 1; break; } } if(flag) { cnt = 0; for(int j = 1; j <= n; j++) { if(cnt == k[i]) break; if(t[i] > book[j]) cnt++, book[j] = t[i] + d[i]-1, ans += j; } cout << ans << endl; }// for(int j = 1; j <= n; j++)// cout << book[j] << ' ';// cout << endl; else cout << -1 << endl; } } return 0;}
- Codeforces Round #387 (Div. 2) C && coedeforces 744 C Servers(水题)
- Codeforces Round #387 (Div. 2) C. Servers
- Codeforces Round #387 (Div. 2) C. Servers
- Codeforces Round #387 (Div. 2)C. Servers(模拟)
- Codeforces Round #387 (Div. 2) D && coedeforces 744 D. Winter Is Coming(贪心)
- Codeforces Round #387(Div. 2)C. Servers【模拟】
- Codeforces Round #387 (Div. 2)C. Servers(模拟)
- Codeforces Round #387 (Div. 2) 747C Servers
- Codeforces Round #387 (Div. 2) Servers
- Codeforces Round #387 (Div. 2) C
- Codeforces Round #287 (Div. 2) C
- Codeforces Round #291 (Div. 2)(C)
- 【codeforces】Codeforces Round #370 (Div. 2) C
- C. Star sky(Codeforces Round #427 (Div. 2) C)
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #153 (Div. 2) C题
- 大作业(一)
- 线程同步
- maven setting.xml文件配置详情
- 技能包!Linux 下清空或删除大文件内容的 5 种方法
- code vs 3160 最长公共子串(后缀自动机)
- Codeforces Round #387 (Div. 2) C && coedeforces 744 C Servers(水题)
- C++练习:用指针实现栈
- 删除ztree树
- c++公有继承、保护继承和私有继承
- 从源码角度深入分析ant
- 欧拉计划 3
- ssh: connect to host localhost port 22: Connection refused
- 学习笔记:GoogLeNet
- struts2运行流程