# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529334 | kevin | 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>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";
#define nl cout<<"\n"
const int MOD = 1e9 + 7;
vector<int> find_subset(int l, int r, vector<int> ar){
sort(all(ar));
int n = ar.size();
int sm = 0;
int p = 0;
vector<int> emp = {};
if(ar[0] > l) return emp;
for(int i=0; i<n; i++){
if(ar[i] + sm > r) break;
sm += ar[i];
p = i;
}
for(int i=0; i<=n; i++){
if(sm >= l && sm <= r){
vector<int> out = {};
for(int j=i; j<=p+i; j++){
out.push_back(j);
}
return out;
}
if(i + 1 + p >= n) break;
sm -= ar[i];
sm += ar[i+p+1];
}
return emp;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
// if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
vector<int> v = (find_subset(15, 17, {6, 8, 8, 7}));
ca(v);
}