碎碎念
第一行三个整数 n,L,v 分别表示魔法的种类数,山坡的长度,Sisyphus 的速度。
第二行 n 个整数。第 i 个整数 a_i 表示第 i 个魔法作用的位置。(1<i<n)
第三行一个整数 q 表示宙斯的询问个数。
接下来 q 行每行一个整数,第 i 行的整数 t_i 表示宙斯的第 i 个询问。(1<i<n)
输出 q 行,每行恰好一个整数,第 i行的整数对应第 i 个询问的答案。(1≤i≤q)
如果宙斯无论如何都不能使 Sisyphus 使用的年数大于 t_i ,请输出 −1。
输入 #1
3 6 3
3 5 1
4
1
3
4
5
输出 #1
0
1
2
-1
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, l;
double v;
cin >> n >> l >> v;
vector<double> a(n);
vector<double> b(n);
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end(), greater<int>());
b[0] = a[0] / v;
for(int i = 1 ; i < n; ++i) {
a[i] += a[i - 1];
b[i] = a[i] / v;
}
int q, t;
cin >> q;
double T = l / v;
int cnt;
for(int i = 0; i < q; ++i) {
cin >> t;
if(T > t) {
cout << 0 << endl;
} else {
cnt = upper_bound(b.begin(), b.end(), t - T) - b.begin();
if (cnt >= n) {
cout << -1 << endl;
} else {
cout << cnt + 1 << endl;
}
}
}
}