QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783971#9529. Farm ManagementXuntongdaRE 0ms0kbC++141.1kb2024-11-26 12:29:152024-11-26 12:29:15

Judging History

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

  • [2024-11-26 12:29:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 12:29:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,t;
long long ans,m,maxx;
struct s{
	long long w,l,r,v;
}a[100010];
bool cmp(s a,s b){
	if(a.w>b.w)return 1;
	else{return 0;
	}
}
int main(){
	ios::sync_with_stdio(0);
	freopen("farm02.in","r",stdin);
	freopen("farm02.out","w",stdout);
	cin>>t;
	while(t--){
		ans=0,maxx=0;;
		cin>>n>>m;
		for(int i=1;i<=n;i++){
			cin>>a[i].w>>a[i].l>>a[i].r;
			a[i].v=a[i].r-a[i].l;
			m-=a[i].l;
			ans+=a[i].w*a[i].l;
		}
		sort(a+1,a+1+n,cmp);
		long long h=m+a[1].l,cnt=ans-(a[1].w*a[1].l);
		maxx=max(maxx,cnt+(h*a[1].w));
		for(int i=n;i>=1;i--){
			long long h=m+a[i].l,cnt=ans-(a[i].w*a[i].l);
			//cout<<h<<" "<<cnt<<endl;
			for(int j=1;j<=n;j++){
				if(j==i)continue;
					if(a[j].v>h){
						cnt+=h*a[j].w;
						//cout<<cnt<<endl;
						h=0;
						break;
					}
					if(a[j].v<=h){
						cnt+=a[j].v*a[j].w;
						//cout<<cnt<<endl;
						h-=a[j].v;
					}
				
			}
			maxx=max(maxx,cnt);
			//cout<<endl;
			//cout<<maxx<<" "<<h<<" "<<cnt<<endl;
		}
		cout<<maxx<<"\n";
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

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

output:


result: