fork download
  1. #include <bits/stdc++.h>
  2. #include "molecules.h"
  3. #define ff first
  4. #define ss second
  5. using namespace std;
  6.  
  7. vector<int> find_subset(int l, int u, vector<int> w) {
  8. int N =w.size();
  9. vector< pair<int,int> > ws;
  10. for(int i =0; i < N; i++) ws.push_back(make_pair(w[i],i));
  11. sort(begin(ws),end(ws));
  12. vector<long long> sums(N+1,0);
  13. for(int i =0; i < N; i++) sums[i+1] =sums[i]+ws[i].ff;
  14. if(sums[N] < l) return vector<int>();
  15. int a =0;
  16. while(a < N && sums[a] < l) a++;
  17. for(int i =N; i > 0; i--) {
  18. while(a > 0 && sums[N]-sums[i]+sums[a] > u) a--;
  19. if(sums[N]-sums[i]+sums[a] >= l && sums[N]-sums[i]+sums[a] <= u) {
  20. vector<int> ans;
  21. for(int j =0; j < a; j++) ans.push_back(ws[j].ss);
  22. for(int j =i; j < N; j++) ans.push_back(ws[j].ss);
  23. return ans;}
  24. }
  25. return vector<int>();}
  26.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:23: fatal error: molecules.h: No such file or directory
compilation terminated.
stdout
Standard output is empty