# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1129419 | svorogaze | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> find_subset(int l, int r, vector<int> ve) {
vector<pair<int, int>> w;
for (int i = 0; i < ve.size(); ++i) {
w.push_back({ve[i], i});
}
sort(w.begin(), w.end());
for (int i = 0; i < w.size(); ++i) {
if (w[i].first >= l && w[i].first <= r) return {w[i].second + 1};
}
int kek = accumulate(ve.begin(), ve.end(), 0ll);
if (kek >= l && kek <= r) {
vector<int> rs(ve.size());
iota(rs.begin(), rs.end(), 1ll);
return rs;
}
int sm = w[0].first;vector<int> ans;
for (int i = 1; i < w.size(); ++i) {
sm += w[i].first;
if (sm >= l && sm <= r) {
for (int j = 0; j <= i; ++j) {
ans.push_back(w[j].second + 1);
}
return ans;
}
int xx = sm - w[0].first + w.back().first;
if (xx >= l && xx <= r) {
for (int j = 1; j <= i; ++j) {
ans.push_back(w[j].second + 1);
}
ans.push_back(w.back().second + 1);
}
}
return {};
}