# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946742 | PenguinsAreCute | Mutating DNA (IOI21_dna) | 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;
using ll = long long;
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<pair<int,int>> ww(n);
for(int i=0;i<n;i++) ww[i]={w[i],i};
sort(w.begin(),w.end());
sort(ww.begin(),ww.end());
ll pre[n], post[n];
for(int i=-1;++i<n;) pre[i]=w[i]+(i?pre[i-1]:0);
for(int i=n;i--;) post[i]=w[i]+(i==n-1?0:post[i+1]);
for(int i=-1;++i<n;) if(pre[i]<=u&&post[n-1-i]>=l) {
ll cur=pre[i];
vector<int> v(i+1); for(int j=-1;++j<=i;) v[j]=ww[j].second;
if(cur>=l) return v;
for(int j=-1;++j<=min(i,n-i);) {
cur += w[n-1-j] - w[j];
v[j] = ww[n-1-j].second;
if(cur>=l) return v;
}
}
return {};
}
// 26 lines