QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787865#9529. Farm Managementiim76WA 1ms3560kbC++142.6kb2024-11-27 15:00:022024-11-27 15:00:04

Judging History

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

  • [2024-11-27 15:00:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3560kb
  • [2024-11-27 15:00:02]
  • 提交

answer

#include <bits/stdc++.h>

#define endl '\n' 

using namespace std;
using ll = long long;

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

void solve(){
	int n;
	ll m;
	cin >> n >> m;
	vector<ll> prel(n + 1), prewl(n + 1), prelr(n + 1), prewlr(n + 1);
	vector<node> crops(n);
	
	for(int i = 0; i < n; i++){
		cin >> crops[i].w >> crops[i].l >> crops[i].r;
	}
	sort(crops.begin(), crops.end());

	for(int i = 1; i <= n; i++){
		prel[i] = prel[i - 1] + crops[i - 1].l;
		prewl[i] = prewl[i - 1] + crops[i - 1].w * crops[i - 1].l;
		prelr[i] = prelr[i - 1] + crops[i - 1].r - crops[i - 1].l;
		prewlr[i] = prewlr[i - 1] + (crops[i - 1].r - crops[i - 1].l) * crops[i - 1].w; 
	}
	
	m -= prel[n];
	int ans = prewl[n];
	
	int p = upper_bound(prelr.begin() + 1, prelr.end(), prelr[n] - m) - prelr.begin();
	//cerr << p << endl;
	m = m - (prelr[n] - prelr[p]);
	ans += prewlr[n] - prewlr[p];
	 
	for(int i = n - 1; i >= p; i--){
		crops[i].e = crops[i].r - crops[i].l;
	}

	if(m > 0){
		ans += crops[p - 1].w * m;
		crops[p - 1].e = m;
		m = 0;
	}
	
	vector<int> preext(n + 1), prewext(n + 1), sufext(n + 1), sufwext(n + 1);
	for(int i = 1; i <= n; i++){
		preext[i] = preext[i - 1] + crops[i - 1].e;
		prewext[i] = prewext[i - 1] + crops[i - 1].w * crops[i - 1].e;
	}
	
	for(int i = n - 1; i >= 0; i--){
		sufext[i] = sufext[i + 1] + max(0, crops[i].r - crops[i].l - crops[i].e);
		sufwext[i]  = sufwext[i + 1] + max(0, crops[i].r - crops[i].l - crops[i].e) * crops[i].w;
	}
	
	int ext = 0;
	for(int i = 1; i <= n; i++){
		if(crops[i - 1].e == crops[i - 1].r - crops[i - 1].l) continue;
	    int l = preext[i - 1] * crops[i - 1].w - prewext[i - 1];
	    //cerr << l << endl;	    
	    ext = max(ext, l);
	}
	
	for(int i = 0; i < n; i++){
		int r;
		int p = lower_bound(sufext.begin() + i, sufext.end(), crops[i].l + crops[i].e, greater<int>()) - sufext.begin();
		
		if(p == n){
			int t = crops[i].l + crops[i].e;
			r = t * sufwext[p] - t * crops[i].w;
			ext = max(ext, r);
			//cerr << r << endl;
			continue; 
		}
		
	    //p += 1;
		//if(i == 0) cout << p << endl;
	    //assert(crops[i].l + crops[i].e >= sufext[p]);
	    r = sufwext[p] - crops[i].w * (crops[i].e + crops[i].l);
	    if(crops[i].e + crops[i].l > sufext[p]){
	    	int t = crops[i].e + crops[i].l - sufext[p];
	    	r += t * crops[p - 1].w; 
		}
		ext = max(ext, r);
		//cerr << r << endl;
	}
	cout << ans + ext;
}

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

詳細信息

Test #1:

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

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

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:

34859047

result:

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