日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Magic Powder - 2

發布時間:2024/10/5 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Magic Powder - 2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

https://codeforces.com/contest/670/problem/D2

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.

Examples

input

1 1000000000 1 1000000000

output

2000000000

input

10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1

output

0

input

3 1 2 1 4 11 3 16

output

4

input

4 3 4 3 5 6 11 12 14 20

output

3

題意:同上一題,就是數開大了,得用二分 Hait: INF比較小,所以得用3000000000ll就行了

#include <iostream> #include<stdio.h> #include<string.h> using namespace std; typedef long long ll ; ll need[100008]; ll have[100008]; ll tmpp[100008]; ll n,k; ll Slove(ll mid) { ll sum=k;for(ll i=1;i<=n;i++){tmpp[i]=have[i]-mid*need[i];if(tmpp[i]<0)sum+=tmpp[i];if(sum<0)return 0;}return 1; } int main() {while(~scanf("%I64d%I64d",&n,&k)){for(ll i=1;i<=n;i++){scanf("%I64d",&need[i]);}for(ll i=1;i<=n;i++){scanf("%I64d",&have[i]);}ll ans=0;ll mid;ll l=0;ll r=3000000000ll;while(r>=l){mid=(l+r)/2;if(Slove(mid)==1){ans=mid;l=mid+1;}else{r=mid-1;}}printf("%I64d\n",ans);}//cout << "Hello world!" << endl;return 0; }

?

總結

以上是生活随笔為你收集整理的Magic Powder - 2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。