Magic Powder

来源:互联网 发布:汽修教学软件 编辑:程序博客网 时间:2024/06/07 02:28

The term of this problem is the same as the previous one, the only exception — increased restrictions.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Example
Input
1 100000000011000000000
Output
2000000000
Input
10 11000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000001 1 1 1 1 1 1 1 1 1
Output
0
Input
3 12 1 411 3 16
Output
4
Input
4 34 3 5 611 12 14 20
Output
3


一个很标准的二分,但自己还是反应不过来,真的菜的抠脚啊,注意long long,不要超了范围。

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;long long a[100001];long long b[100001];int main(){   long long n,k;   scanf("%I64d %I64d",&n,&k);   for(int i=1; i<=n; i++)   {       scanf("%I64d",&a[i]);   }   for(int i=1; i<=n; i++)   {       scanf("%I64d", &b[i]);   }  long long x = 0;  long long y = 2000000000;  long long minx = 0;  while(x <= y)  {      long long mid = (x+y)/2;      long long kk = k;      long long i;      for(i=1; i<=n; i++)      {        if(mid*a[i] > b[i])        kk -= (mid*a[i]-b[i]);        if(kk<0)break;      }      if(i==n+1) {x=mid+1;minx = max(minx,mid);}      else y=mid-1;  }  printf("%I64d\n",minx);    return 0;}
水波。

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 充电宝充手机慢怎么办 执行局执行不到钱怎么办 小孩挖耳朵疼了怎么办 挖耳朵挖破了怎么办 挖耳朵皮挖破了耳鸣怎么办 北京自考证丢啦怎么办 不服检察院的答复函该怎么办 检察院控申答复函不复怎么办 在看守所里疯了怎么办 第一次吸毒拘留五天第二次会怎么办 被派出所拘留15天怎么办 老公从拘留所出来聪明老婆怎么办 中信信用卡忘记还款了怎么办 监狱的犯人病了怎么办 判缓期间在行政拘留怎么办 法院拘留15天工作怎么办 高血压签定了无期限合同怎么办 法院司法拘留找不到人怎么办 c1骑摩托车要拘留怎么办 欠钱的找不到人怎么办 治安拘留人跑了怎么办 行政拘留拘留所不收应该怎么办 在看守所被打了怎么办 取保候审超过12个月怎么办 拘留20天还没有判刑怎么办 被打了没有证据怎么办 拘留37天后没有放人怎么办 强制执行执行的财产不够怎么办 收到公安局拘留通知家属应该怎么办 对方不出谅解书怎么办 寻衅滋事没抓的 怎么办 公务员政审父母拘留过怎么办 我参与了网赌怎么办 亲人出车祸去世家属怎么办 车牌换了原保险怎么办 北京车牌夫妻变更车险怎么办 赌博拘留15天不交罚款怎么办 给人打了不赔钱怎么办 打了人对方讹钱怎么办 换车了原来的etc怎么办 换异地车牌了etc怎么办