QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687419#9529. Farm Managementwangxi527#WA 0ms3780kbC++171.4kb2024-10-29 18:55:552024-10-29 18:55:55

Judging History

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

  • [2024-10-29 18:55:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-10-29 18:55:55]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

struct Q {
	int w , l , r ;
	inline bool operator <(const Q &x) const {
		return w > x.w ; 
	}
};
#define all(x) x.begin(),x.end() 
#define pii pair<int,int> 
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n , m ; cin >> n >> m ; 
	vector<Q> a(n) ; 
	for(int i = 0 ; i < n ; i ++ ) cin >> a[i].w >> a[i].l >> a[i].r ; 
	sort(all(a)) ; 
	int ans = 0 , now = 0; 
	queue<pii> q ; 
	for(int i = 0 ; i < n ; i ++ ) {
		ans += a[i].w * a[i].l; a[i].r -= a[i].l ;
		now += a[i].l ; 
		q.push({a[i].w,a[i].r}) ; 
	}
	while(q.size() && now < m) {
		auto x = q.front() ; 
		if(x.second <= m - now) {
			ans += x.second * x.first ; 
			now += x.second ; q.pop() ;
		}
		else {
			ans += (m - now) * x.first ; 
			q.front().second -= m - now ; 
			now = m ; break ;
		}
	}
	int res = ans ; 
	for(int i = n - 1 ; i >= 0 ; i -- ) {
		if(q.empty()) break ; 
		res -= a[i].l * a[i].w;
		now -= a[i].l ; 
		while(q.size() && now < m) {
				auto x = q.front() ; 
					if(x.second <= m - now) {
						res += x.second * x.first ; 
						now += x.second ; q.pop() ;
					}
					else {
						res += (m - now) * x.first ; 
						q.front().second -= m - now ; 
						now = m ; break ;
					}
		}
		if(now == m)
		ans = max(ans,res) ; 
	}
	cout << ans << endl ; 
	return 0 ; 
}

詳細信息

Test #1:

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

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

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:

40106857

result:

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