求hack
查看原帖
求hack
1031934
捧着风的少年楼主2023/12/14 15:44

P4053 [JSOI2007] 建筑抢修, 题目求hack

#include <bits/stdc++.h>
using namespace std;
const int N = 150000 + 100;
int n;
struct p
{
	int t, end;
}a[N];
operator < (p a, p b)
{
	return a.end < b.end;
}
priority_queue <int> q;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i].t >> a[i].end;
	}
	sort(a + 1, a + 1 + n);
	int ans = 0;
	int TIME = 0; 
	for(int i = 1; i <= n; i++)
	{
		//printf("i=%d, ans=%d\n", i, ans);
		TIME += a[i].t;
		ans++;
		q.push(a[i].t);
		while(TIME > a[i].end)
		{
			//printf("Take out a[i].t = %d\n", a[i].t);
			int qt = q.top();
			q.pop();
			TIME -= qt;
			ans--;
		}
	}
	cout << ans;
}
2023/12/14 15:44
加载中...