QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691287#9529. Farm ManagementhuangceWA 1ms5708kbC++172.3kb2024-10-31 10:44:302024-10-31 10:44:31

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 10:44:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5708kb
  • [2024-10-31 10:44:30]
  • 提交

answer

/*
 * @Author: dsaDadas11
 * @Date: 2024-06-27 10:33:26
 * @LastEditTime: 2024-10-31 10:44:17
 * @Description: go for it!
 */
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define int ll
using namespace std;
constexpr int N=1e6+7;
constexpr int M=2e3+7;
int n,m;
struct op
{
	int w,l,r;
	bool operator<(const op&rhs) const
	{
		return w<rhs.w;
	}
}a[N];
int suf[N]; // 区间后缀
int sufval[N];
int tmp,ans;
bool check(int x,int mx,int pos)
{
	if(x<=pos)
	{
		if(suf[x]-(a[pos].r-a[pos].l)>=mx) return 1;
		return 0;
	}
	else
	{
		if(suf[x]>=mx) return 1;
		return 0;
	}
}
// bool check2(int x,int mx,int pos)
// {
// 	if(x<=pos)
// 	{
// 		if(suf[x]+(a[pos].r-a[pos].l)>=mx) return 1;
// 		return 0;
// 	}
// 	else
// 	{
// 		if(suf[x]>=mx) return 1;
// 		return 0;
// 	}
// }
void solve()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].w>>a[i].l>>a[i].r;
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		tmp+=a[i].w*a[i].l;
		m-=a[i].l;
	}
	for(int i=n;i>=1;i--)
	{
		suf[i]=suf[i+1]+(a[i].r-a[i].l);
		sufval[i]=sufval[i+1]+a[i].w*(a[i].r-a[i].l);
	}
	// 遍历每一个点,二分
	for(int i=1;i<=n;i++)
	{
		int res=tmp;
		res-=a[i].w*a[i].l;
		int mx=m;
		mx+=a[i].l;
		// 将第i个点全都去掉
		int l=1,r=n;
		while(l<r)
		{
			int mid=(l+r)>>1;
			if(check(mid,mx,i)) l=mid+1;
			else r=mid;
		}
		if(l<=i)
		{
			res+=sufval[l]-a[i].w*(a[i].r-a[i].l);
			mx-=suf[l]-(a[i].r-a[i].l);
		}
		else
		{
			res+=sufval[l];
			mx-=suf[l];
		}
		if(mx>0)
		{
			if(l-1>=1) res+=a[l-1].w*mx;
			else res+=a[i].w*mx;
		}
		ans=max(ans,res);
		// 全取第i个点
		res=tmp;
		mx=m;
		if(mx<=a[i].r-a[i].l)
		{
			res+=a[i].w*mx;
			ans=max(ans,res);
			break;
		}
		mx-=(a[i].r-a[i].l);
		res+=a[i].w*(a[i].r-a[i].l);
		l=1,r=n;
		while(l<r)
		{
			int mid=(l+r)>>1;
			if(check(mid,mx,i)) l=mid+1;
			else r=mid;
		}
		if(l<=i)
		{
			res+=sufval[l]-a[i].w*(a[i].r-a[i].l);
			mx-=suf[l]-(a[i].r-a[i].l);
		}
		else
		{
			res+=sufval[l];
			mx-=suf[l];
		}
		if(mx>0)
		{
			res+=a[l-1].w*mx;
		}
		ans=max(ans,res);
	}
	cout<<ans<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T=1; //cin>>T;
	while(T--){solve();}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5708kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

36232275

result:

wrong answer 1st lines differ - expected: '35204500', found: '36232275'