题目的大致意思是有k克的魔法面粉,可以变成任意一种面粉。要做一个饼干,需要n中面粉。第二行是做一个饼干所需要的第i种面粉的量。第三行是第i种面粉的含量。求最多能做多少个饼干。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; long long n, k, a[100010], b[100010]; bool judge(long long x) { long long res = k; for (long long i = 0; i < n; i++) { if (x > b[i]/a[i] ) { if (res < a[i]*x - b[i]) return false; else res -= a[i]*x - b[i]; } } return true; } int main() { while (scanf("%lld%lld", &n, &k) != EOF) { for (long long i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (long long j = 0; j < n; j++) { scanf("%lld", &b[j]); } long long lb = 0, ub = 2e9 + 10; long long ans = 0; while (ub >= lb) { long long mid = (lb + ub)/2; if (judge(mid)) { ans = mid; lb = mid + 1; } else ub = mid - 1; } printf("%lld ", ans); } return 0; }