# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
484485 | _Body | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 204 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"grader.cpp"
#include<bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<int>res;
vector<pair<long long,int>>arr;
int n=w.size();
for(int i=0;i<n;i++)
{
if(w[i]>=l&&w[i]<=u)
{
res.push_back(i+1);
return res;
}
// if(w[i]<l)
// {
arr.push_back({w[i],i});
// }
}
sort(arr.begin(),arr.end());
long long sum=0;
///int l=0;
deque<int>deq;
bool is=false;
for(int i=0;i<arr.size();i++)
{
deq.push_back(arr[i].second);
sum+=arr[i].first;
if(sum>=l&&sum<=u)
{
is=true;
break;
}
if(sum>u)
{
while(sum>u)
{
sum-=(w[deq.front()]);
deq.pop_front();
}
if(sum<=u&&sum>=l)
{
is=true;
break;
}
}
}
if(!is)
{
vector<int>em(0);
return em;
}
long long tmp=0;
for(auto x:deq)
res.push_back((x+1));
for(int rr:res)
tmp+=(w[rr-1]);
if(tmp>u)
{
int x=1/0;
}
if(tmp!=sum)
int x=1/0;
return res;
}
/*
4 15 17
6 8 8 7
*/
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... |