# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
380154 | vishesh312 | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 492 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"molecules.h"
#include"bits/stdc++.h"
using namespace std;
using ll = long long;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<ll, int>> v;
for (int i = 0; i < (int)w.size(); ++i) {
v.push_back({w[i], i});
}
int n = w.size();
sort(v.begin(), v.end());
ll sum = 0;
vector<int> pre, suf;
for (int i = 0; i < n; ++i) {
if (sum + v[i].first > u) {
break;
}
sum += v[i].first;
pre.push_back(v[i].second);
}
if (sum >= l) {
return pre;
}
for (int i = n-1; i >= 0; --i) {
if (pre.size() + suf.size() == n or pre.size() == suf.size()) {
break;
}
suf.push_back(v[i].second);
}
deque<int> dq(pre.begin(), pre.end());
for (int i = 0; i < (int)pre.size(); ++i) {
sum -= w[pre[i]];
sum += w[suf[i]];
dq.pop_front();
dq.push_back(suf[i]);
if (sum >= l and sum <= u) {
vector<int> ret(dq.begin(), dq.end());
return ret;
}
}
vector<int> ret;
return ret;
}
/*
int main() {
int l, r, n;
cin >> l >> r >> n;
vector<int> v(n);
for (auto &x : v) cin >> x;
v = find_subset(l, r, v);
for (auto x : v) cout << x << " ";
}
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |