求助
查看原帖
求助
537520
DESTRUCTION_3_2_1楼主2021/12/6 22:17
#include<bits/stdc++.h>
#define MAXN 100005
using namespace std;
typedef long long ll;
int n,head,tail,cost;
struct node{
	int price,time,used;
}a[MAXN];
inline int read(){
    char ch=getchar();int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;}
int main(){
	ios::sync_with_stdio(false);
	n=read();
	for(int i=0;i<n;i++)
	{
		int m,price_,time_;
		m=read();price_=read();time_=read();
		if(m==0)
		{
			cost+=price_;
			a[tail].price=price_;
			a[tail++].time=time_+45;
		}
		else
		{
			while(head<tail&&a[head].time<time_)
				head++;
			int found=0;
			for(int j=head;j<tail;j++)
			{
				if(a[j].price>=price_&&a[j].used==0)
					found=1;
					a[j].used=1;
					break;
			}
			if(found==0)cost+=price_;
		}
	}
	cout<<cost<<endl;
    return 0;
}

2021/12/6 22:17
加载中...