https://www.luogu.com.cn/record/33284034
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 2 * 100000 + 10;
int a[MAX], b[MAX];
bool book[MAX];
bool cmp(const int& a, const int& b) {
return a > b;
}
inline int read() {
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return x;
}
int main() {
// freopen("endless.in", "r", stdin);
// freopen("endless.out", "w", stdout);
int n = read(), l = read(), v = read();
for (int i = 0; i < n; ++i) a[i] = read();
sort(a, a + n, cmp);
for (int i = 0; i < n; ++i) b[i] = a[i];
int q = read();
while (q--) {
int t = read();
bool ok = 0;
int ans;
//枚举使用魔法的次数
for (int i = 0; i <= n; ++i) {
double y = 0.0;
int w = 0;
if (!i) { //不使用魔法
for (y = 0.0; w < l; ++y, w += v);
// printf("y = %lf\n", y);
if (y > t) { ok = 1; ans = i; break; }
else { continue; } //需要使用魔法
}
else {
sort(b, b + i - 1);
for (int j = 0; j < i; ++j) {
//下去又上来,相当于时间乘2
y += b[j] * 1.0 / v * 2;
w += b[j];
}
y += (l - w) * 1.0 / v;
// printf("y = %lf\n", y);
if (y > t) { ok = 1; ans = i; break; }
else { continue; }
}
}
printf("%d\n", ok ? ans : -1);
}
return 0;
}