救命!!!!95ptsTLE了!!!
查看原帖
救命!!!!95ptsTLE了!!!
644509
an_ancient_ghoul楼主2022/7/3 15:12

记录: 记录
code:

#include<bits/stdc++.h>
using namespace std;
int n, m1, m2, t, ans=0;
int a1[100100], a2[100100], cnt1=0, cnt2=0;
int pad1[100100], pad2[100100];
inline int read() {
	register int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9')x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}
struct an
{
	int a, b;
	
	bool operator> (an ud)const
	{
		if (this->a > ud.a)return 1;
		return 0;
	}
}pls;
priority_queue<an,vector<an>,greater<an> > q1,q2;
int main()
{
	ios_base::sync_with_stdio(0);
	n = read(), m1 = read(), m2 = read();
	for (int i = 1; i <= m1; i++)
	{
		pls.a = read(),pls.b=read();
		q1.push(pls);
	}
	for (int i = 1; i <= m2; i++)
	{
		pls.a = read(),pls.b=read();
		q2.push(pls);
	}
	while (!q1.empty())
	{
		t = 0, pls = q1.top(), q1.pop();
		for (int i = 1; i <= cnt1&&i<=n; i++)
		{
			if (pad1[i] <= pls.a)
			{
				t=1,pad1[i] = pls.b, a1[i]++;
				break;
			}
		}
		if (!t)
		{
			pad1[++cnt1] = pls.b, a1[cnt1]++;
		}
	}
	while (!q2.empty())
	{
		t = 0, pls = q2.top(), q2.pop();
		for (int i = 1; i <= cnt2&&i<=n; i++)
		{
			if (pad2[i] <= pls.a)
			{
				t=1,pad2[i] = pls.b, a2[i]++;
				break;
			}
		}
		if (!t)
		{
			pad2[++cnt2] = pls.b, a2[cnt2]++;
		}
	}
	for (int i = 1; i <= n; i++)a1[i] += a1[i - 1];
	for (int i = 1; i <= n; i++)a2[i] += a2[i - 1];
	for (int i = 0; i <= n; i++)ans = max(ans, a1[i] + a2[n - i]);
	cout << ans;
	return 0;
}
2022/7/3 15:12
加载中...