刷新,最快最小
2023-09-21 20:29:39
发布于:上海
14阅读
0回复
0点赞
600K+20ms
自己理解代码
#include <stdio.h>
struct tic{
int t, m;
};
tic queue[100001];
int head=0, tail=0, tmptail=0;
int n, s=0, tmp;
int type, price, time__;
int main(){
scanf("%d", &n);
while(n--){
scanf("%d%d%d", &type, &price, &time__);
if(type==0){
s += price;
queue[tail].t = time__;
queue[tail].m = price;
tail++;
}
else{
tmp = 0;
tmptail = tail;
while(head<tmptail){
if(time__-queue[head].t<=45){
if(price<=queue[head].m){
head++;
tmp = 1;
break;
}
queue[tail++] = queue[head];
}
head++;
}
if(!tmp) s += price;
while(head<tmptail){
queue[tail++] = queue[head++];
}
}
if(head==tail) head=tail=0;
}
printf("%d", s);
return 0;
}
这里空空如也
有帮助,赞一个