Description:

有n棵树,初始时每棵树的高度为 Hi,第 i 棵树每月都会长高Ai。现在有个木料长度总量为 S 的订单,客户要求每块木料的长度不能小于 L ,而且木料必须是整棵树(即不能为树的一部分)。现在问你最少需要等多少个月才能满足订单。

Input:

第一行3个用空格隔开的非负整数 n,S,L表示树的数量、订单总量和单块木料长度限制。
第二行n个用空格隔开的非负整数,依次为 H 1 , H 2 , , H n H_{1},H_{2},…,H_{n} H1,H2,,Hn
第三行n个用空格隔开的非负整数,依次为 A 1 , A 2 , , A n A_{1} ,A_{2} ,…,A_{n} A1,A2,,An

Output:

输出一行一个整数表示答案。

Sample Input:

3 74 51
2 5 2
2 7 9

Sample Output:

7

题目连接

每颗树的高度和生长天数是一次关系,所以直接在数据范围内二分生长天数找到答案。
题目数据很大,会爆long long,所以一定要使用unsigned long long。

AC代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6+5;
const double eps = 1e-5;
const double pi = asin(1.0)*2;
const double e = 2.718281828459;

int n;
ull s, l;
ull h[maxn];
ull a[maxn];
ull d[maxn];
ull ans;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    while (cin >> n >> s >> l) {
        ull a_max = 0;
        for (int i = 0; i < n; ++i) {
            cin >> h[i];
        }
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            if (a[i] > a_max) {
                a_max = a[i];
            }
        }
        ull _left = 0;
        ull _right = s > l ? s : l;
        _right /= a_max;
        _right += 1000;
        while (_left < _right) {
            ll mid = (_left + _right) / 2;
            ll sum = 0;
            for (int i = 0; i < n; ++i) {
                d[i] = h[i] + a[i] * mid;
                if (d[i] >= l) {
                    sum += d[i];
                }
            }
            if (sum < s) {
                _left = mid + 1;
            }
            else {
                _right = mid;
            }
            ans = _right;
        }
        cout << ans << endl;
    }
    return 0;
}