QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691009#9529. Farm ManagementAaWA 1ms5688kbC++171.3kb2024-10-31 09:24:042024-10-31 09:24:06

Judging History

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

  • [2024-10-31 09:24:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5688kb
  • [2024-10-31 09:24:04]
  • 提交

answer

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
struct Node{
	int w,l,r;
	bool operator<(const struct Node&W)const{
		return w>W.w;
	}
}node[100010];
int s[100010],s1[100010],s2[100010];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		int w,l,r;
		cin >> w >> l >> r;
		node[i]={w,l,r};
		m-=l;
	}
	sort(node+1,node+1+n);
	for(int i=1;i<=n;i++){
		int w=node[i].w,l=node[i].l,r=node[i].r;
		s[i]=s[i-1]+r-l;
		s1[i]=s1[i-1]+r*w;
		s2[i]=s2[i-1]+l*w;
//		cout << w << " " << l << " " << r << endl;
	}
	int res=0;
	for(int i=1;i<=n;i++){
		int w=node[i].w,l=node[i].l,r=node[i].r;
		int rest=m+l;
		int left=0,right=n;
		while(left<right){
			int mid=(left+right)/2+1;
			int cost=s[mid];
			if(mid>=i) cost+=l;
			if(cost<=rest) left=mid;
			else right=mid-1;
		}
		int revenue=s1[right];
		rest-=s[right];
		if(right>=i) rest-=l;
		right++;
		if(right==i) revenue+=w*rest;
		else revenue+=node[right].w*(node[right].l+rest);
		if(right<n){
			revenue+=s2[n]-s2[right];
			if(right<i) revenue-=l*w;
		}		
//		cout << w << " " << l << " " << r << " " << right << " " << revenue << endl;
		res=max(res,revenue);
	}
	cout << res;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5628kb

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: 0ms
memory: 5688kb

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'