# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029527 | nisanduu | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<long long> w) {
vector<ll> pref;
int n = w.size();
for(ll i=0;i<n;i++){
pref.push_back(w[i]);
}
vector<int> ans;
for(ll i=1;i<w.size();i++){
pref[i]=pref[i-1]+pref[i];
}
for(ll i=0;i<w.size();i++){
ll target = i != 0 ? pref[i-1] : 0;
target += l;
ll ub = (target-l) + u;
ll left = i,right = n-1;
ll ind = i;
while(left<=right){
ll mid = left + (right-left)/2;
if(pref[mid]<target){
left = mid+1;
}else if(pref[mid]>ub){
right = mid-1;
}else{
ind = mid;
right = mid-1;
}
}
if(pref[ind]>=target&&pref[ind]<=ub){
for(ll j=i;j<=ind;j++){
ans.push_back(j);
}
return ans;
}
}
return ans;
}