跳到正文

题解

题解:P16749 [GKS 2020 #A] Workout

wuzhenduo约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年6月7日
收录
2026年7月2日
更新
2026年11月8日
篇幅
约 1 分钟
题目
P16749

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,t[2000000],c[2000000],maxx;
int main()
{
	cin>>n>>k>>m;
	for(int i=1;i<=n;i++){
		cin>>t[i]>>c[i];
		maxx=max(t[i],maxx);
	}
	long long l=m,r=maxx,mid,z;
	while(l<=r){
		mid=(l+r)/2;
		long long ans=0;
		for(int i=1;i<=n;i++){
			if(t[i]>mid){
				ans+=(t[i]-mid)*c[i];
			}
		}
		if(ans<=k){
			z=mid;
			r=mid-1;
		}
		else{
			l=mid+1;
		}
	}
	cout<<z;
    return 0;
}
原文