Submission #530735

#TimeUsernameProblemLanguageResultExecution timeMemory
530735CyanmondDetecting Molecules (IOI16_molecules)C++17
31 / 100
3 ms580 KiB
#include <bits/stdc++.h>

using i64 = int64_t;
template <typename T> using Vec = std::vector<T>;

std::vector<int> find_subset(int L, int R, std::vector<int> W) {
    const int N = (int)W.size();
    std::vector<int> order(N);
    std::iota(order.begin(), order.end(), 0);
    std::sort(order.begin(), order.end(),
              [&](const int a, const int b) { return W[a] < W[b]; });
    {
        std::vector<int> new_W(N);
        for (int i = 0; i < N; ++i) {
            new_W[i] = W[order[i]];
        }
        W = std::move(new_W);
    }

    int min = *std::min_element(W.begin(), W.end());
    for (auto &e : W) {
        e -= min;
    }
    std::vector<i64> C(N + 1);
    for (int i = 0; i < N; ++i) {
        C[i + 1] = C[i] + W[i];
    }

    for (int i = 1; i <= N; ++i) {
        const i64 base = i * (i64)min;
        if (base > R) continue;

        const i64 l = L - base, r = R - base;
        const i64 x = C[i], y = C[N] - C[N - i];
        if (l <= y and x <= r) {
            std::vector<int> answer(i);
            std::iota(answer.begin(), answer.end(), 0);

            i64 now = x;
            for (int j = i - 1; j >= 0; --j) {
                const int p = N - (i - j);
                if (now + (W[p] - W[j]) <= r) {
                    now += W[p] - W[j];
                    answer[j] = p;
                } else {
                    int v = j;
                    while (now + (W[v + 1] - W[v]) <= r) ++v;
                    answer[j] = v;
                    break;
                }
            }

            for (auto &e : answer) e = order[e];
            return answer;
        }
    }

    return {};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...