# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
942817 | irmuun | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 424 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;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
vector<int>find_subset(int l,int u,vector<int>w){
int n=(int)w.size();
vector<pair<ll,int>>v(n);
ll L=l,U=u,tot=0;
for(int i=0;i<n;i++){
v[i].ff=w[i];
v[i].ss=i;
}
sort(all(v));
int r=0;
vector<int>ans;
for(int i=0;i<n;i++){
if(tot+v[i].ff<=u){
tot+=v[i].ff;
r=i+1;
ans.pb(i);
}
else{
break;
}
}
if(r==0) return {};
if(r==n&&tot<l) return {};
if(l<=tot&&tot<=r){
for(auto &x:ans){
x=v[x].ss;
}
return ans;
}
ll curr=n-1;
for(int i=(int)ans.size()-1;i>=0;i--){
if(tot-v[ans[i]].ff+v[curr].ff<l){
tot=tot-v[ans[i]].ff+v[curr].ff;
ans[i]=curr;
curr--;
}
else{
for(int j=i+1;j<=curr;j++){
tot=tot-v[ans[i]].ff+v[j].ff;
ans[i]=j;
if(l<=tot) break;
}
break;
}
}
if(tot<l) return {};
for(auto &x:ans){
x=v[x].ss;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |