#include <cstdio>
#include <vector>
#include <cassert>
#include<bits/stdc++.h>
#include "molecules.h"
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();
int f=0;
for(int i=1;i<v.size();i++)
{
lf=i;
if(ck(i))
{
f=1;
break;
}
}
if(f==0)
{
cout<<-1<<<endl;
vector<int>ans;
return ans;
}
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;
ms.insert(z);
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: In function 'bool ck(int)':
molecules.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++)
~^~~~~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w.size();i++)v.push_back({w[i],i});
~^~~~~~~~~
molecules.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<v.size();i++)
~^~~~~~~~~
molecules.cpp:48:19: error: expected primary-expression before '<' token
cout<<-1<<<endl;
^
molecules.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=lf;i<v.size();i++)rm.insert(v[i]);
~^~~~~~~~~