题目链接:
http://codeforces.com/contest/670/problem/D2
题解:
二分答案。
#include<iostream> #include<cstdio> #include<cstring> #include<map> using namespace std; const int maxn = 100000 + 10; const int INF = 2e9; typedef __int64 LL; int n, k; int x[maxn], y[maxn]; bool solve(int num, LL kk) { for (int i = 0; i < n; i++) { if ((LL)x[i] * num>y[i]) { kk -= ((LL)x[i] * num - y[i]); } if (kk < 0) return false; } return true; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", x + i); for (int i = 0; i < n; i++) scanf("%d", y + i); int l = 0, r = INF + 1; while (l < r - 1) { int mid = l + (r - l) / 2; if (solve(mid, k)) l = mid; else r = mid; } printf("%d ", l); return 0; }