# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
574403 | Elias | 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>
#ifndef _DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include "molecules.h"
#endif
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w)
{
n = w.size();
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++)
a[i] = {w[i], i};
sort(a.begin(), a.end());
if (a[0].first > u)
return {};
if (a.back().first >= l && a.back().first <= u)
return {n - 1};
if (a[0].first >= l && a[0].first <= u)
return {0};
int i = 0;
int sum = 0;
for (int j = 0; j < n; j++)
{
sum += a[j].first;
while (sum > u)
{
sum -= a[i].first;
i++;
}
if (sum >= l)
{
vector<int> out;
for (int k = i; k < j; k++)
{
out.push_back(a[k].first);
}
return out;
}
}
return {};
}
#ifdef _DEBUG
signed main()
{
int n, l, u;
cin >> n >> l >> u;
vector<int> a(n);
for (int &x : a)
cin >> x;
for (int x : find_subset(l, u, a))
cout << x << " ";
}
#endif