# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685695 | Bliznetc | 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>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC target("avx2")
using namespace std;
#define pb push_back
#define sz size()
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define int long long
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef vector < vi > vvi;
vi find_subset(int l, int u, vi w) {
int n = w.sz;
pii a[n + 7];
int sum = 0;
for (int i = 1; i <= n; i++) {
a[i]= {w[i - 1], i};
sum += a[i].F;
}
sort (a + 1, a + n + 1);
if (sum < l) {
return {};
}
int r = u;
if (a[1].F > u) {
return {};
}
int cur = 0;
int ptr = 0;
vi result;
for (int i = 1; i <= n; i++) {
if (cur + a[i].F >= l) {
if (cur + a[i].F <= r) {
cur += a[i].F;
result.pb(a[i].S);
}
break;
}
cur += a[i].F;
result.pb(a[i].S);
}
if (cur < l) {
for (int i = 0; i < result.sz; i++) {
if (cur - a[i].F + a[n].F <= r) {
result[i] = a[n].S;
break;
}
}
}
if (cur >= l && cur <= r) {
return result;
}
return {};
}
/*
void solve(){
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
int l = 15, u = 17;
int a[4] = {6, 8, 8, 7};
int result[10];
int pos = find_subset(l, u, a, 4, result);
cout << pos;
// cin >> t;
// while (t--) {
// solve();
// cout << "\n";
// }
}
*/