显示原始代码
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, num[N], day, cnt;
long x, a[N], b[N];
bool cmp(int u, int y) {
if (a[u] == a[y])
return u < y;
return a[u] < a[y];
}
int counttotal(int s) {
if (s == 1)
return 1;
else if (s == 2)
return 2;
else if (s == 3)
return 4;
else if (s % 2 == 0)
return (s * s + 2 * s) / 4;
else
return counttotal(s - 1) + (s + 1) / 2;
}
int findday(int l, int r) {
while (l <= r) {
int mid = (l + r) / 2;
if (counttotal(mid) < cnt)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++) num[i] = i;
cin >> m;
sort(num + 1, num + n + 1, cmp);
for (int i = 1; i <= m; i++) {
cin >> x;
day = 0, cnt = 0;
for (int j = 1; j <= n; j++) {
if (x > a[num[j]]) {
x += b[num[j]];
} else {
cnt += a[num[j]] - x + 1;
x = b[num[j]] + a[num[j]] + 1;
}
}
if (cnt == 0)
day = 0;
else
day = findday(1, cnt);
cout << day << ' ';
}
return 0;
}