QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691417#9529. Farm ManagementhuangceWA 1ms5676kbC++172.7kb2024-10-31 11:23:422024-10-31 11:23:55

Judging History

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

  • [2024-10-31 11:23:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5676kb
  • [2024-10-31 11:23:42]
  • 提交

answer

/*
* @Author: dsaDadas11
* @Date: 2024-06-27 10:33:26
* @LastEditTime: 2024-10-31 11:04:59
* @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);
	}
	// 遍历每一个点,二分
	//cout<<"m: "<<m<<endl;
	//cout<<tmp<<endl;
	for(int i=1;i<=n;i++)
	{
		int res=tmp;
		res-=a[i].w*a[i].l;
		int mx=m;
		mx+=a[i].l;
		//cout<<"mx: "<<mx<<endl;
		// 将第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;
		}
		l++;
		//cout<<"l: "<<l<<endl;
		if(l<=i)
		{
			// cout<<"l: "<<l<<"   i: "<<i<<endl;
			// cout<<"suf[l]: "<<suf[l]<<"   suf[i]: "<<i<<endl;
			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);
			continue;
		}
		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;
		}
		l++;
		//cout<<"l: "<<l<<endl;
		if(l<=i)
		{
			// cout<<"l: "<<l<<"   i: "<<i<<endl;
			// cout<<"suf[l]: "<<suf[l]<<"   suf[i]: "<<suf[i]<<endl;
			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];
			//cout<<"mx***: "<<mx<<endl;
			//cout<<"l: "<<l<<"   i: "<<i<<endl;
		}
		if(mx>0)
		{
			res+=a[l-1].w*mx;
		}
		ans=max(ans,res);
		//cout<<"ans: "<<ans<<endl;
	}
	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: 5636kb

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: 0
Accepted
time: 1ms
memory: 5676kb

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:

35204500

result:

ok single line: '35204500'

Test #3:

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

input:

15 32
835418 2 3
178262 1 3
527643 2 2
519710 1 1
774544 3 3
82312 1 1
808199 1 1
809396 1 3
255882 1 3
80467 1 3
874973 1 3
813965 1 2
198275 1 2
152356 1 3
802055 1 1

output:

17015002

result:

wrong answer 1st lines differ - expected: '22000255', found: '17015002'