using namespace std;
long long a,b,lf,rt,mid;
vector<pair<int,int> >v;
bool ck(int x)
{
long long cnt=0,sum=0;
for(int i=0;i<v.size();i++)
{
cnt++;
sum+=v[i].first;
if(cnt==x)break;
}
if(sum>b)return 0;
cnt=0,sum=0;
for(int i=v.size()-1;i>=0;i--)
{
cnt++;
sum+=v[i].first;
if(cnt==x)break;
}
if(sum<a)return 0;
return 1;
}
vector<int> find_subset(int l, int u, std::vector<int> w)
{
a=l,b=u;
for(int i=0;i<w.size();i++)v.push_back({w[i],i});
sort(v.begin(),v.end());
lf=0,rt=v.size();
while(lf<rt)
{
mid=(lf+rt)/2;
if(ck(mid))lf=mid+1;
else rt=mid;
}
lf--;
multiset<pair<long long,int> >ms,rm;
long long sum=0;
for(int i=0;i<lf;i++)
{
sum+=v[i].first;
ms.insert(v[i]);
}
for(int i=lf;i<v.size();i++)rm.insert(v[i]);
while(sum<a)
{
pair<int,int>z=*ms.begin();
sum-=z.first;
ms.erase(ms.begin());
z=*--rm.end();
sum+=z.first;
rm.erase(--rm.end());
}
vector<int>ans;
multiset<pair<long long,int> >::iterator it;
for(it=ms.begin();it!=ms.end();it++)
{
pair<int,int>z=*it;
ans.push_back(z.second);
}
return ans;
}
Compilation message
molecules.cpp:3:1: error: 'vector' does not name a type
vector<pair<int,int> >v;
^~~~~~
molecules.cpp: In function 'bool ck(int)':
molecules.cpp:7:19: error: 'v' was not declared in this scope
for(int i=0;i<v.size();i++)
^
molecules.cpp:15:15: error: 'v' was not declared in this scope
for(int i=v.size()-1;i>=0;i--)
^
molecules.cpp: At global scope:
molecules.cpp:24:1: error: 'vector' does not name a type
vector<int> find_subset(int l, int u, std::vector<int> w)
^~~~~~