作者:念 | 来源:互联网 | 2023-10-12 14:09
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.
【分析】可能有更简单的方法吧,我这个方法比较笨,直接循环模拟时间(天数)。
#include iostream
#include cstring
#include cstdio
#include algorithm
#include cmath
#include string
#include map
#include stack
#include queue
#include vector
#define inf 10000000000000
#define met(a,b) memset(a,b,sizeof a)
#define lson l,m,rt 1
#define rson m+1,r,rt 1|1
typedef long long ll;
using namespace std;
const int N = 1e6+;
const int M = 4e5+;
int n,m,k,tot=;
struct man{
int k,d;
}a[N];
int main()
{
//int vis[1000000];
int mark[];
met(mark,);
int s,t,t1,t2,p,dir;
scanf("%d%d", n,
while(m--){
scanf("%d%d%d", s, t, t1);
a[s].k=t;a[s].d=t1;
}
tot=n;
for(int i=;i i++){
//if(i==15)printf("!!!%d\n",a[15].k);
//printf("i=%d\n",i);
if(!a[i].k){
tot=;
for(int j=;j j++){
if(mark[j])mark[j]--;
if(mark[j] )tot++;
//printf("#%d\n",j,mark[j]);
}
continue;
}
//printf("!!!%d %d\n",i,tot);
if(tot a[i].k){
printf("-1\n");
tot=;
for(int j=;j j++){
if(mark[j])mark[j]--;
if(mark[j] )tot++;
//printf("#%d\n",j,mark[j]);
}
continue;
}
else {
tot=;
p=a[i].k;
int sum=;
for(int j=;j j++){
if(mark[j]== p!=){
mark[j]=a[i].d;
sum+=j;
p--;
}
if(mark[j])mark[j]--;
if(mark[j] )tot++;
}
printf("%d\n",sum);
}
}
return ;
}