QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790284#9529. Farm Managementiim76WA 0ms3768kbC++141.8kb2024-11-28 09:44:322024-11-28 09:44:34

Judging History

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

  • [2024-11-28 09:44:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2024-11-28 09:44:32]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct node{
	int w, l, r;
	
	bool operator<(const node & other)const{
		return w < other.w;
	}
};

void solve(){
	int n;
	ll m;
	cin >> n >> m;
	ll t = m;
	vector<node> crops(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> crops[i].w >> crops[i].l >> crops[i].r;
	}
	sort(crops.begin() + 1, crops.end());
	
	vector<ll> prel(n + 5), prewl(n + 5), prelr(n + 5), prewlr(n + 5);
	for(int i = 1; i <= n; i++){
		prel[i] = prel[i - 1] + crops[i].l;
		prewl[i] = prewl[i - 1] + crops[i].l * crops[i].w;
		prelr[i] = prelr[i - 1] + crops[i].r - crops[i].l;
		prewlr[i] = prewlr[i - 1] + (crops[i].r - crops[i].l) * crops[i].w;
	}
	
	ll ans = prewl[n];
	t -= prel[n];
	
	//prelr[n] - prelr [l] <= m 
	int p = lower_bound(prelr.begin() + 1, prelr.begin() + n + 1, prelr[n] - t) - prelr.begin();
	
	if(p == n + 1)
	{
		ans += crops[p - 1].w * t;
		t = 0;
	}else{
		t -= prelr[n] - prelr[p];
		ans += prewlr[n] - prewlr[p];	
		ans += t * crops[p].w;
	}

	
	for(int i = 1; i <= n; i++){
		ll s = m;
		s -= prel[n];
		ll res = prewl[n];
		s += crops[i].l;
		res -= crops[i].l * crops[i].w;
//		cout << res << " " << s;
//		cout << endl;
		
		//prelr[n] - prelr[l] <= s
		//假如多开数组避免特判,则要注意开始和结束位置 
		int p1 = lower_bound(prelr.begin() + i + 1, prelr.begin() + n + 1, prelr[n] - s) - prelr.begin();
		
		if(p1 == n + 1){
			res += crops[p1 - 1].w * s;
			s = 0;
		}else{
			res += prewlr[n] - prewlr[p1];
			//cout << res << endl;		
			s -= prelr[n] - prelr[p1];		
			res += s * crops[p1].w;			
		}	
		ans = max(ans, res);	
	}
	cout << ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	solve();
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

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

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

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:

22079365

result:

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