F - Financial Planning Gym - 102007F 【 二分答案 】

2023-03-09 19:28:51 浏览数 (1)

BAPC 2018  The 2018 Benelux Algorithm Programming Contest  &:对于需要的天数来二分,然后验证,注意的是 r 的数据不能开的太小或者太大。

代码语言:javascript复制
#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("%lldn",l);
    return 0;
}

0 人点赞