| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1369005 | kismis | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int u, vector<int>& w) {
int n = w.size();
// Sort indices by weight
vector<int> idx(n);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int a, int b) {
return w[a] < w[b];
});
// Feasibility check: total sum must reach l
long long total = 0;
for (int i : idx) total += w[i];
if (total < l) return {};
// Greedy prefix sum
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += w[idx[i]];
if (sum >= l) {
// By the problem guarantee, sum <= u holds here
return vector<int>(idx.begin(), idx.begin() + i + 1);
}
}
return {}; // unreachable if feasibility check passed
}