#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
vector< pair<ll, ll> >vec;
ll u, l;
std::vector<int> find_subset(int L, int U, std::vector<int> w) {
for(ll a=0; a<w.size(); a++)
vec.pb({w[a], a});
sort(vec.begin(), vec.end());
ll ptr=0, sum=vec[0].f, u=U, l=L, ptr2=1;
bool flag=false;
for(ll a=1; a<vec.size(); a++)
{
if(sum<=u && sum>=l)
{
flag=true;
ptr2=a;
break;
}
sum+=vec[a].f;
if(sum<=u && sum>=l)
{
flag=true;
ptr2=a+1;
break;
}
while(sum>u)
{
sum-=vec[ptr].f;
ptr++;
}
}
if(!flag)
{
vector<int>yo;
yo.clear();
return yo;
}
vector<int>yo;
for(ll a=ptr; a<ptr2; a++)
{
yo.pb(vec[a].s);
}
return yo;
}
int main() {
int n, l, u;
assert(3 == scanf("%d %d %d", &n, &l, &u));
std::vector<int> w(n);
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &w[i]));
std::vector<int> result = find_subset(l, u, w);
printf("%d\n", (int)result.size());
for (int i = 0; i < (int)result.size(); i++)
printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll a=0; a<w.size(); a++)
~^~~~~~~~~
molecules.cpp:18:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll a=1; a<vec.size(); a++)
~^~~~~~~~~~~
/tmp/cc7YzlWY.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccx77C4j.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status