【50.00%】【codeforces 747C】Servers
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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.
Output
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.
Examples
input
4 3
1 3 2
2 2 1
3 4 3
output
6
-1
10
input
3 2
3 2 3
5 1 2
output
3
3
input
8 6
1 3 20
4 2 1
6 5 5
10 1 1
15 3 6
21 8 8
output
6
9
30
-1
15
36
Note
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).
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.
【题目链接】:http://codeforces.com/contest/747/problem/C
【题解】
一个任务一个任务地枚举
因为时间是升序的、所以不用管。
在枚举的时候看看这个任务开始的时候有哪些人是空闲的?
->如何确定某个人是否空闲???
->这个人完成任务的时间.
每让一个人接任务过后,就记录每个人任务完成的时间是什么时候.
时间复杂度O(n*q);
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXP = 1e2+10;
const int MAXQ = 1e5+10;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
struct abc
{
int t,k,d;
};
int last[MAXP];
abc a[MAXQ];
int n,q;
int b[MAXP];
int ans[MAXQ];
int sum[MAXP];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(q);
rep1(i,1,q)
{
rei(a[i].t);rei(a[i].k);rei(a[i].d);
}
rep1(i,1,q)
{
b[0] = 0;
sum[0] = 0;
rep1(j,1,n)
if (last[j]<a[i].t)
{
b[0]++;
b[b[0]] = j;
sum[b[0]] = sum[b[0]-1]+b[b[0]];
if (b[0]==a[i].k)
break;
}
if (b[0]==a[i].k)
{
ans[i] = sum[b[0]];
rep1(j,1,b[0])
last[b[j]] = a[i].t + a[i].d-1;
}
else
ans[i] = -1;
}
rep1(i,1,q)
printf("%d\n",ans[i]);
return 0;
}
【50.00%】【codeforces 747C】Servers的更多相关文章
- 【50.00%】【codeforces 602C】The Two Routes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- 【25.00%】【codeforces 584E】Anton and Ira
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【50.88%】【Codeforces round 382B】Urbanization
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【74.00%】【codeforces 747A】Display Size
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- SQLServer —— 变量的使用
一.局部变量的定义与赋值 定义语法: -- 声明一个局部变量 DECLARE @变量名 数据类型 -- 声明多个局部变量 DECLARE @变量名1 数据类型1, @变量名2 数据类型2 赋值语法: ...
- Person Re-identification 系列论文笔记(八):SPReID
Human Semantic Parsing for Person Re-identification Kalayeh M M, Basaran E, Gokmen M, et al. Human S ...
- poj2391 最大流+拆点
题意:F块草坪,上面有n头牛,可以容纳m个牛遮雨.将草坪一份为2,成为二部图. 对于此题,和poj2112很像,只是2112很明显的二部图.这道题就开始敲,但是建图遇到问题,草坪的2个值怎么处理,于是 ...
- ACM:树的变换,依据表达式建立表达式树
题目:输入一个表达式.建立一个表达式树. 分析:找到最后计算的运算符(它是整棵表达式树的根),然后递归处理! 在代码中.仅仅有当p==0的时候.才考虑这个运算符,由于括号中的运 ...
- Directx11学习笔记【八】 龙书D3DApp的实现
原文:Directx11学习笔记[八] 龙书D3DApp的实现 directx11龙书中的初始化程序D3DApp跟我们上次写的初始化程序大体一致,只是包含了计时器的内容,而且使用了深度模板缓冲. D3 ...
- 快速删除项目中的输出日志console.log
项目开发时,控制台往往有许多忘记删除或注释掉的输出日志.但是上线后总不能一个一个删吧,最近总结出几个解决思路 重写console.log方法,使其失去 输出能力 这个最直接有效,用vue框架的话放在m ...
- 【NS2】NS2 教學手冊(转载)
之前做毕设的时候搜索NS2的相关资料,发现这个里面涵盖很广,特此收藏,感谢原作者的辛勤劳作. NS2 教學手冊 ( NS2 Learning Guide) [快速連結區] My works 中文影音 ...
- Maven启用代理访问
如果你的公司正在建立一个防火墙,并使用HTTP代理服务器来阻止用户直接连接到互联网.如果您使用代理,Maven将无法下载任何依赖. 为了使它工作,你必须声明在 Maven 的配置文件中设置代理服务器: ...
- 可变形参 Day07
package com.sxt.kebianxingcan; /* * 可变形参 * 声明:数据类型...标识符 * 作用:将实参作为数组处理 * 规则:一个方法只能有一个可变形参并且作为最后一个形参 ...
- 开发者说:Sentinel 流控功能在 SpringMVC/SpringBoot 上的实践
从用户的视角来感受一个开源项目的成长,是我们推出「开发者说」专栏的初衷,即在开发者进行开源项目选型时,提供更为立体的项目信息.专栏所有内容均来自作者原创/投稿,本文是「开发者说」的第6篇,作者 Jas ...