有没有大佬帮忙看一下为什么超时
查看原帖
有没有大佬帮忙看一下为什么超时
764919
lpout楼主2022/10/7 13:10

这道题开O2的话会AC,不开就超限 有没有大佬看一下怎么优化

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<cmath>
using namespace std;
struct go{
	int seq;
	int time;
	int coin;
}a[100001];
struct prize{
	int ot;
	int ex;
	int wh;
	int us;
}b[100001];
int main()
{
	int n,i,j,p,d;
	int k=0;int ans =0;int flag=0;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d %d %d",&a[i].seq,&a[i].coin,&a[i].time);
	}
	for (i=0;i<n;i++)
	{
		if(a[i].seq==0)
		{
			b[k].ex=a[i].coin;
			b[k].ot=a[i].time+45;
			b[k].us=1;
			b[k].wh=i;
			ans+=a[i].coin;
			k++;
		}
		else if(a[i].seq==1)
		{
			p=i;
			while (a[i].time-a[p].time<=45)
			{
				p--;
			}
			d=0;
			while (b[d].wh<p)
			{
				d++;
			}
			for (j=d;j<k;j++)
			{
				if (b[j].ex>=a[i].coin && b[j].ot>=a[i].time && b[j].us==1)
				{
					b[j].us=0;
					flag=1;
					break;
				}
			}
			if (flag==1)
			{
				flag=0;
				continue;
			}
			else
			{
				flag=0;
				ans+=a[i].coin;
			}
		}
	}
	printf("%d",ans);
	return 0;
}
2022/10/7 13:10
加载中...