# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
380454 | Dan4Life | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 364 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>
#include "molecules.h"
using namespace std;
vector<int> find_subset(int l, int r, vector<int> w) {
int n = (int)w.size(), sum = 0, z=0;
vector<pair<int,int> > v;
vector<int> ans, x;
for(auto u : w) v.push_back({u,z++});
sort(v.begin(),v.end());
for(int i = 0; i < n; i++)
{
int num = v[i].first, index = v[i].second;
if(sum+num<=r)sum+=num, ans.push_back(index), x.push_back(num);
else{
if(sum>=l) return ans;
int MN = l-sum, MX = r-sum;
for(int j = i; j < n; j++)
{
int num = v[j].first, index = v[j].second;
//1 1 8 8 6 10 6 8
int pos = lower_bound(x.begin(),x.end(),num-MX)-x.begin();
if(pos!=x.size() and sum-x[pos]+num>=l and sum-x[pos]+num<=r){
ans.erase(ans.begin()+pos); ans.push_back(index); return ans;
}
}
ans.clear();
return ans;
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |