# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886911 | artixkrishna | 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>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define REP(i,a,b) for(int i=a; i<b; i++)
vector<int> find_subset(int l, int u, vector<int> w){
int n=w.size();
vector<pair<int,int>> arr(n);
REP(i,0,n){
arr[i].first = w[i];
arr[i].second =i;
}
sort(arr.begin(), arr.end());
ll sum=0;
int a=0, b=0;
int a1=a; int b1=b;
sum+=(ll)arr[0].first();
while(b<n){
while(b+1<n&& sum<l){
b++;
sum+=(ll)arr[b].first;
}
while(a<b && sum>u){
sum-=(ll)arr[a].first;
a++;
}
if(sum>=l && sum<=u) break;
if(b==n&&a+1==b) return vector<int>(0);
if(b==b1 && a==a1) return vector<int>(0);
a1=a; b1=b;
}
vi ans;
REP(i,a,b+1) ans.push_back(arr[i].second);
return ans;
}