QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687263#9529. Farm ManagementMENDAX#WA 0ms5700kbC++201.4kb2024-10-29 17:54:102024-10-29 17:54:11

Judging History

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

  • [2024-10-29 17:54:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5700kb
  • [2024-10-29 17:54:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
#define pii pair<ll,ll>
#define mp make_pair
const int N = 1e5 + 10;
pair<ll,pii> p[N];
ll ans,res,pre[N],finans,val[N];

void solve(int x) {
	ll nowres = res + p[x].second.first;
	ll now = ans - p[x].second.first * p[x].first;
	int l=1,r=x-1;
	while(l<r){
		int mid=(l+r+1)/2;
		if(pre[mid]<=x) l=mid;
		else r=mid-1;
	}
	int pos = l;
	//cout <<"debug:x:" <<x << "nowres:" << nowres << "now:"<<now<< "pos:"<<pos <<"\n";
	now += val[pos];nowres -= pre[pos];
	if (nowres) now += p[pos].first * nowres;
	finans = max(finans,now);
}

signed main() {
	ios::sync_with_stdio(false);
	cin >>n >>m;
	for (int i = 1;i <= n;++i) {
		ll x,l,r;cin >> x >> l >> r;
		p[i] = mp(x,mp(l,r));
	} 
	sort(p+1,p+1+n);
	reverse(p+1,p+1+n);
	//从大到小
	res = m;
	for (int i = 1;i <= n;++i) {
		ans += (p[i].second.first) * p[i].first;
		res -= p[i].second.first;
		pre[i] = pre[i-1] + (p[i].second.second - p[i].second.first);
		val[i] = val[i-1] + (p[i].second.second - p[i].second.first) * p[i].first;
	} 
	//printf("pre:");for (int i = 1;i <= n;++i) cout <<pre[i] << " "; cout << "\n"; 
	//printf("val:");for (int i = 1;i <= n;++i) cout <<val[i] << " "; cout << "\n"; 
	finans = ans;
	for (int i = 1;i <= n;++i) {
		solve(i);
	}
	cout << finans;
}

/*
3 20
1 10 11
2 9 10
3 1 20
3 10
1 1 10
2 9 10
100000 0 10

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

113

result:

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