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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

codeforce之Magic Powder

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

題目:

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.


解答:

首先很很明顯這是一個對結果進行二分的題目,

注意要用long long int,同時在判斷目標答案是否可行的時候用減法不要用加法,否則可能會溢出

#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <map> #include <vector> #include <algorithm> #define ll long long int using namespace std;struct vege {ll id;ll per;ll total;ll alre;vege() {} };ll cost(vector<vege> &ingr, int tar,ll k) {ll res = 0;ll size = ingr.size();for (int i = 0; i < size; ++i) {if (k < 0)return false;k = k - (tar *ingr[i].per - ingr[i].total <= 0 ? 0 : tar *ingr[i].per - ingr[i].total);}if (k < 0)return false;return true; } static bool comp(vege A, vege B) {return A.alre < B.alre; } int main() {ll n, k;cin >> n >> k;vector<vege> ingr(n);ll per;for (int i = 0; i < n; ++i) {cin >> per;ingr[i].id = i;ingr[i].per = per;}for (int i = 0; i < n; ++i) {cin >> per;ingr[i].total = per;ingr[i].alre = per / ingr[i].per;}//sort(ingr.begin(), ingr.end(), comp);int l = 0;int r = ~(1 << 31);int res = 0;while (l <= r) {int mid = l + (r - l) / 2;bool co = cost(ingr, mid, k);if (co) {l = mid + 1;res = mid;}else {r = mid - 1;}}cout << res << endl;//system("pause"); }

總結

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

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