# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026372 | ezzzay | 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<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
#define pb push_back
#define ff first
#define ss second
signed main(){
int l,u;
cin>>l>>u;
int n;
cin>>n;
vector<int> w;
for(int i=0;i<n;i++){
int a;
cin>>a;
w.pb(a);
}
vector<pair<int,int>>vc;
for(int i=0;i<n;i++){
vc.pb({w[i],i});
}
sort(vc.begin(),vc.end());
int L=0,R=-1;
int s=0;
int x=-1,y=-1;
while(1){
if(s<l){
R++;
s+=vc[R].ff;
}
else if(l<=s and s<=u){
x=L;
y=R;
break;
}
else{
s-=vc[L].ff;
L++;
}
if(R==n-1)break;
}
vector<int>ans;
for(int i=x;i<=y;i++){
ans.pb(vc[i].ss);
}
return ans;
}