# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169520 | 2019-12-20T18:50:38 Z | anubhavdhar | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> #define ll long long int #define FOR(i,N) for(i=0;i<N;i++) #define FORe(i,N) for(i=1;i<=N;i++) #define FORr(i,a,b) for(i=a;i<b;i++) #define ii pair<ll,ll> #define vi vector<ll> #define vii vector<ii> #define ff first #define ss second #define mp make_pair #define pb push_back using namespace std; #include "molecules.h" /* const ll MAXN = 1e5+5; const ll INF = 1e17 + 9; const ll MOD = 1e9 + 7; const ll INT_BITS = 31; const ll LOGN = 17; */ #define MAXN 200005 vector<int> find_subset(int l,int u,vector<long int>w) { //cout<<"p\n"; ll N,i,j,k; //cin>>N; N = w.size(); sort(w.begin(),w.end()); ll sum = 0; vector<int> v; //cout<<"l = "<<l<<" and r = "<<u<<" and N = "<<N<<" after sorting\n"; FOR(i,N) { //cout<<w[i]<<" "; sum += w[i]; } if(sum < l) return v; //cout<<endl; sum = w[0]; if (sum > u) return v; i = 0; j = 0; while(j < N and i < N and i<=j) { //cout<<"entering with i = "<<i<<" and j = "<<j<<" and sum = "<<sum<<endl; if(sum > u) { i++; if (i > j) return v; sum -= w[i-1]; //cout<<"reducing sum to "<<sum<<endl; } else if(sum < l) { j++; sum += w[j]; //cout<<"increasing sum to "<<sum<<endl; } //cout<<"after manupulation sum = "<<sum<<endl; if (sum >= l and sum <= u) { //cout<<"got something\n"; for(k = i;k <= j;k++) v.pb(k); break; } } return v; } /* int main() { ll i,n,u,l; cin>>n>>l>>u; vector<int> w(n); FOR(i,n) cin>>w[i]; //cout<<"input taken\n"; vector<int> v; v = find_subset(l,u,w); FOR(i,v.size()) cout<<v[i]<<endl; return 0; } */