#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
map<pii,short> memo;
int S[200005];
int A[100005];
bool possible(int i,int L,int R)
{
if(L<0 || i==0 || S[i]<L) return false;
if(L<=A[i] && A[i]<=R) return true;
if(memo[pii(i,L)]==0){
bool ans=possible(i-1,L-A[i],R-A[i]) || possible(i-1,L,R);
if(ans) memo[pii(i,L)]=1;
else memo[pii(i,L)]=-1;
}
if(memo[pii(i,L)]==-1) return false;
else return true;
}
void createSubset(vector<int>& ans,int i,int L,int R)
{
if(L<=A[i] && A[i]<=R){
ans.push_back(i-1);
return;
}
if(possible(i-1,L-A[i],R-A[i])){
ans.push_back(i-1);
createSubset(ans,i-1,L-A[i],R-A[i]);
}
else{
createSubset(ans,i-1,L,R);
}
}
vector<int> find_subset(int l, int r, vector<int> w) {
for(int i=0;i<w.size();i++){
A[i+1]=w[i];
}
for(int i=1;i<=n;i++){
S[i]=S[i-1]+A[i];
}
vector<int> subset;
if(possible(w.size(),l,r)){
createSubset(subset,w.size(),l,r);
}
return subset;
}
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w.size();i++){
~^~~~~~~~~
molecules.cpp:38:20: error: 'n' was not declared in this scope
for(int i=1;i<=n;i++){
^