# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101297 | chunghan | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
//#include"molecules.h"
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pii> p;
vector<int> rst;
vector<lld> S;
int a = 0, b = 0, sum = 0;
for (int i = 0; i < (int)w.size(); i++)
p.push_back(pii(w[i], i));
sort(p.begin(), p.end());
S.push_back(p[0].first);
for (int i = 1; i < (int)p.size(); i++)
S.push_back(S[i-1] + p[i].first);
while (1) {
if (sum > u) sum -= S[a++];
else if (b >= w.size()) break;
else if (sum < l) sum += S[b++];
else if ((sum >= l && sum <= u)) break;
}
if (b < w.size())
for (int i = a+1; i <= b; i++)
rst.push_back(p[i].second);
return rst;
}
int main() {
vector<int> w;
w.push_back(15);
w.push_back(16);
w.push_back(17);
w.push_back(18);
vector<int> r = find_subset(10, 20, w);
for (int i = 0; i < r.size(); i++) cout << r[i] << ' ';
return 0;
}