0分求助
查看原帖
0分求助
1008766
Coookie楼主2023/12/2 22:11

蒟蒻用了老师教的代码,结果0分,还特意下了一个数据,运行之后也没问题,神犇看下有什么问题吗?

#include<iostream>
using namespace std;

struct ticket
{
	int price,time;
	bool used;
} a[100005];

int main()
{
	int n,cnt,ans;
	cin >> n;
	int pos = 1;
	for (int i = 1;i <= n;i++)
	{
		int op,price,time;
		cin >> op >> price >> time;
		if (!op)
		{
			ans += price;
			cnt++;
			a[cnt].price = price;
			a[cnt].time = time + 45;
		}
		else
		{
			bool flag = false;
			for (int j = pos;j <= cnt;j++)
			{
				if (price <= a[j].price && time <= a[j].time && !a[j].used)
				{
					a[j].used = true;
					flag = true;
					break;
				}
				if (time > a[j].time)
				{
					pos = j + 1;
				}
			}
			if (!flag)
			{
				ans += price;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

悬赏关注1月~

2023/12/2 22:11
加载中...