# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
465231 | dattranxxx | Detecting Molecules (IOI16_molecules) | C++11 | 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.
/*
* Author : shora
*/
#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cerr << _ << ' ';} cerr << endl;
#include "molecules.h"
using namespace std;
using ll = long long;
const int oo = 1e9;
const int N = 1e4, U = 1e4;
int dp[U + 1];
int n;
vector<int> find_subset(int l, int u, vector<int> a) {
n = a.size();
a.insert(a.begin(), 0);
sort(a.begin() + 1, a.end());
vector<int> pre(n+2), suf(n+2);
for (int i = 1; i <= n; ++i) {
pre[i] = pre[i-1] + a[i];
suf[i] = suf[i-1] + a[n-i+1];
}
vector<int> res;
for (int k = 1; k <= n; ++k) {
if (pre[k] <= u && suf[k] >= l) {
for (int i = 0; i <= k; ++i) if (l <= pre[i] + suf[k-i] && pre[i] + suf[k-i] <= u) {
for (int j = 1; j <= i; ++j) res.push_back(j-1);
for (int j = 1; j <= k-i; ++j) res.push_back(n-j);
return res;
}
}
}
return res;
}
int main() {
int l, u;
cin >> n >> l >> u;
vector<int> a(n);
for (int& x : a)
cin >> x;
vector<int> res = find_subset(l, u, a);
print(res);
}