# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156552 | 2019-10-06T13:34:19 Z | InfiniteJest | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include <iostream> #include <fstream> #include <vector> #include <queue> #include <algorithm> #include <math.h> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); typedef long long ll; int n; int ls,rs; int v[100001]; int res[100001]; pair<int,int> p[100001]; int find_subset(int l, int u, int[] w, int n, int[] result){ int s=-1; int d=n-1; int sum=0; bool flag=0; for(int i=0;i<n;i++){ p[i].fi=w[i]; p[i].se=i; } sort(p,p+n); while(s<n){ if(sum>u)break; while((sum<l||sum>u)&&d>s){ sum+=p[d].fi; d--; } d++; if(sum>=l&&sum<=u){ flag=1; break; } sum-=p[d].fi; s++; sum+=p[s].fi; } if(flag){ for(int i=0;i<=s;i++)res[i]=p[i].se; for(int i=n-1;i>=d;i--)res[s+(n-1-i)+1]=p[i].se; return s+1+n-d; } return 0; }