BAPC 2018 The 2018 Benelux Algorithm Programming Contest
&:对于需要的天数来二分,然后验证,注意的是 r 的数据不能开的太小或者太大。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
ll p, c;
} vis[100005];
int main()
{
ll n,m;
scanf("%lld %lld", &n, &m);
for(int i = 1; i <= n; i ++)
{
scanf("%lld %lld",&vis[i].p, &vis[i].c);
}
ll l = 1;
ll r = 4000000009;
while(l < r)
{
ll mid = (l + r) / 2;
ll ans= 0;
for (int i = 1; i <= n; i ++) // 验证答案
{
if(vis[i].p * mid - vis[i].c > 0)
{
ans += (vis[i].p *mid - vis[i].c);
if(ans >= m) break;
}
}
if(ans >= m) r = mid;
else l = mid + 1;
}
printf("%lld\n",l);
return 0;
}
标签:Financial,Gym,102007F,mid,long,vis,ans,ll,lld From: https://blog.51cto.com/u_15965659/6056712