显示原始代码
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, day, cnt;
long x, a[N], b[N];
map<long, int> num;
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;
long max = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
num[a[i]] = i;
if (max < a[i])
max = a[i];
}
for (int i = 1; i <= n; i++) cin >> b[i];
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> x;
day = 0, cnt = 0;
for (long j = 1; j <= max; j++) {
if (x > a[num[j]])
x += b[num[j]];
else {
cnt += a[num[j]] - x + 1;
x = a[num[j]] + b[num[j]] + 1;
}
}
if (cnt == 0)
day = 0;
else
day = findday(1, cnt);
cout << day << ' ';
}
return 0;
}