# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
778099 | vjudge1 | Detecting Molecules (IOI16_molecules) | C++17 | 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;
const int N = 8e5+37;
#define int long long
void f(){
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
vector<int> find_subset(int l, int u, vector<int> w) {
int n= w.size();
vector<array<int, 2>> a(n);
for(int i=0; i<n; i++){
a[i]={w[i], i};
}
sort(a.begin(), a.end());
if(a[0][0]>u)
return vector<int>(0);
int sum=0, k=-1;
for(int i=0; i<n&&k==-1; i++){
if(sum+a[i][0]>l){
k=i;
}
else{
sum+=a[i][0];
}
}
if(k==-1) return std::vector<int>(0);
if(k==0){
vector<int> ans(1);
ans[0]=a[0][1]+1;
return ans;
}
sum-=a[0][0];
sum+=a[n-1][0];
if(sum<l||sum>u) return std::vector<int>(0);
vector<int> ans;
for(int i=1; i<k; i++){
ans.push_back(a[i][1]+1);
}
ans.push_back(a[n-1][1]+1);
sort(ans.begin(), ans.end());
return ans;
}
/*
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
f();
int n; cin >> n;
int u, v; cin >> u>>v;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
auto x= find_subset(u, v, a);
cout<<n<<"\n";
for(auto i: x) cout<<i<<" ";
cout<<"\n";
}*/