# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
651341 | ayalla | Detecting Molecules (IOI16_molecules) | C++14 | 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 "molecules.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long int
#define endl '\n'
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 500001
#define mod 1000000007
vector<int> find_subset(int l, int u, vector<int> w)
{
int r = u;
int n = w.size();
set<pi> s;
int sum = 0;
for (int i = 0; i < n; i++)
{
s.insert({w[i], i});
sum += w[i];
}
vector<bool> vis(n, 1);
while (sum > r)
{
int dif = sum - r;
auto it = s.lower_bound({dif, -1});
if (it != s.end() && (sum - (*it).fir) >= l && (sum - (*it).fir) <= r)
{
pi x = *it;
sum -= x.fir;
vis[x.sec] = 0;
break;
}
else
{
pi x = *s.begin();
sum -= x.fir;
vis[x.sec] = 0;
s.erase(x);
}
}
if (sum < l)
return {};
vector<int> ans;
for (int i = 0; i < n; i++)
{
if (vis[i])
ans.pb(i);
}
return ans;
}
// r + min >= max + l
// r - max >= l - min