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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

CodeForces 670D2 Magic Powder - 2

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

Description
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.

Sample Input
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
題意:給出材料種類n, 和魔法值k,再給出做一個蛋糕需要每種的材料的數目,和已存每種材料數目,魔法可以變成材料,求最多可以做多少蛋糕

#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define LL __int64 #define M 100100LL k, a[M], b[M], asum, bsum, n; bool find(LL x)//判斷做 x 份蛋糕夠不夠 {LL sum = 0, all = k;//all 表示剩余多少魔法 for(int i=1; i<=n; i++){if(a[i] * x > b[i])//不夠則用魔法補 {all -= (a[i] * x - b[i]);}if(all < 0) return false;//魔法不夠就只好退出 }return true; } int main() {while(scanf("%I64d%I64d", &n, &k) != EOF){asum = bsum = 0;for(int i=1; i<=n; i++){scanf("%d", &a[i]);asum += a[i];}for(int i=1; i<=n; i++){scanf("%d", &b[i]);bsum += b[i];}LL right, left, mid, ans;left = 0, right = (bsum + k) / asum;//都平均一下看看最多能做多少蛋糕 while(right >= left){mid = (right + left) >> 1;if(find(mid)){ans = mid;left = mid + 1; }else{right = mid - 1;}}printf("%I64d\n", ans);}return 0; }

總結

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

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