QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697711#9529. Farm ManagementRFIYWA 1ms5720kbC++171.6kb2024-11-01 15:26:362024-11-01 15:26:38

Judging History

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

  • [2024-11-01 15:26:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5720kb
  • [2024-11-01 15:26:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 1e7 + 10;

struct st{
	ll w, l, r;
}p[N], a[N];

bool cmp(st x, st y){
	return x.w < y.w;
}

ll sum[N], sum1[N];

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	ll n, m;
	
	cin >> n >> m;
	
	for(int i = 0; i < n; i ++){
		cin >> p[i].w >> p[i].l >> p[i].r;
	}
	
	sort(p, p + n, cmp);
	
	ll ans = 0, res = 0;
	
	for(int i = 0; i < n; i ++){
		ans += p[i].w * p[i].l;
		res += p[i].l;
	}
	
	ll ans1 = ans + (m - res) * p[n - 1].w;
	ll cnt = n - 1;
	
	for(int i = n - 1; i >= 0; i --){
		ll cur = min(m - res, p[i].r - p[i].l);
		
		ans += p[i].w * cur;
		res += cur;
		p[i].l += cur;
		
		if(res == m){
			cnt = i;
			break;
		}
	}
	
	//cout << '\n'; for(int i = 0; i < n; i ++) cout << p[i].w << ' ' << p[i].l << ' ' << p[i].r << '\n';
	
	for(int i = cnt; i >= 0; i --){
		sum[i] = sum[i + 1] + p[i].r - p[i].l;
		sum1[i] = sum1[i + 1] + p[i].w * (p[i].r - p[i].l);
	}
	
	for(int i = 0; i <= cnt; i ++){
		ll cur = p[i].l, ti = p[i].l, now = ans - p[i].w * p[i].l;
		
		p[i].l = 0;
		
		ll l = 0, r = cnt;
		
		while(l < r){
			ll mid = (l + r) / 2;
			if(sum[mid] > cur){
				l = mid + 1;
			}
			else{
				r = mid;
			}
		}
		
		now += min(cur, sum[r]) * p[r].w, cur -= min(cur, sum[r]);
		r --;
		
		while(cur && r){
			ll ti = min(cur, p[r].r - p[r].l);
			cur -= ti;
			now += p[r].w * ti;
			r --;
		}
		
		p[i].l = ti;
		
		ans1 = max(ans1, now);
	}
	
	cout << ans1;
	
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5720kb

input:

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

output:

103

result:

wrong answer 1st lines differ - expected: '109', found: '103'