日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

codeforce之Magic Powder

發布時間:2024/1/1 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

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