20pts求调
查看原帖
20pts求调
917150
lyb7512楼主2025/1/9 21:48

除#1#2AC外全部WA。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5 + 5;
struct node
{
	int l, r;
};
node s[MAXN];
int a[MAXN];
int b[MAXN];
int t;
int n, m, k, p;
int minn;
priority_queue<int> pq;
bool check(int x)
{
	while(!pq.empty())
	{
		pq.pop();
	}
	int sum = 0;
	int tot = 0;
	memset(b, 0, sizeof(b));
	int cur = 1;
	for(int i = 1; i <= n; i ++)
	{
		sum += b[i];
		int temp = a[i] + sum;
		if(temp < x)
		{
			while(!pq.empty() && pq.top() < i)
			{
				pq.pop();
			}
			while(cur <= m && s[cur].l <= i)
			{
				if(s[cur].l >= i)
				{
					pq.push(s[cur].r);
				}
				cur ++;
			}
			int cnt = (x - temp) / p;
			if((x - temp) % p)
			{
				cnt ++;
			}
			if(tot + cnt > k)
			{
				return false;
			}
			tot += cnt;
			for(int j = 1; j <= cnt; j ++)
			{
				if(!pq.empty() && pq.top() >= i)
				{
					sum += p;
					b[pq.top() + 1] -= p;
					pq.pop();
				}
				else
				{
					return false;
				}
			}
		}
	}
	return true;
}
int dich()
{
	int l = minn - 1;
	int r = minn + k * p + 1;
	while(l + 1 < r)
	{
		int mid = (l + r) / 2;
		if(check(mid) == true)
		{
			l = mid;
		}
		else
		{
			r = mid;
		}
	}
	return l;
}
bool cmp(node x, node y)
{
	if(x.l != y.l)
	{
		return x.l < y.l;
	}
	return x.r > y.r;
}
signed main()
{
	cin >> t;
	while(t --)
	{
		cin >> n >> m >> k >> p;
		minn = 1e9;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
			minn = min(minn, a[i]);
		}
		for(int i = 1; i <= m; i ++)
		{
			cin >> s[i].l >> s[i].r;
		}
		sort(s + 1, s + m + 1, cmp);
		cout << dich() << endl;
	}
	return 0;
}

是没清空吗?还是其它问题?

2025/1/9 21:48
加载中...