未了题解

cookiebus 2020-10-31 9:09:17 8

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
long long t,n, a[400010], ans[400010];

struct Query {
    int q, idx;
};
Query p[400010];

bool cmp(long long a, long long b) {
    return a > b;
}

bool cmp2(Query a, Query b) {
    return a.q < b.q;
}

int main(){
    long long n, L, v, q;
    cin >> n >> L >> v;
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
    }
    sort(a + 1, a + n + 1, cmp);

    double total = L * 1.0 / v;
    
    cin >> q;
    for (int i = 1; i <= q; ++i) {
        scanf("%d", &p[i].q);
        p[i].idx = i;
    }
    
    sort(p + 1, p + q + 1, cmp2);
    
    int cur = 0;
    for (int i = 1; i <= q; ++i) {

        while (cur <= n && total <= p[i].q) {
            cur ++;
            total += a[cur] * 1.0 / v;
        }
        if (cur > n)
            ans[p[i].idx] = -1;
        else
            ans[p[i].idx] = cur;
    }

    for (int i = 1; i <= q; ++i)
        printf("%lld\n", ans[i]);

    return 0;
}
{{ vote && vote.total.up }}