QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697558#9529. Farm ManagementRFIYWA 0ms3588kbC++171.1kb2024-11-01 14:49:002024-11-01 14:49:01

Judging History

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

  • [2024-11-01 14:49:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-11-01 14:49:00]
  • 提交

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];

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

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){
			cnt = i;
			break;
		}
	}
	
	for(int i = 0; i <= cnt; i ++){
		ll cur = p[i].l, ti = p[i].l, j = cnt, now = ans - p[i].w * p[i].l;
		
		p[i].l = 0;
		
		while(cur && j){
			cur -= min(cur, p[j].r - p[j].l);
			now += p[j].w * min(cur, p[j].r - p[j].l);
			j --;
		}
		
		p[i].l = ti;
		
		ans1 = max(ans1, now);
	}
	
	cout << ans1;
	
	
	
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3588kb

input:

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

output:

99

result:

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