Submission #631729

#TimeUsernameProblemLanguageResultExecution timeMemory
631729lucriDetecting Molecules (IOI16_molecules)C++17
100 / 100
56 ms10660 KiB
#include <cstdio> #include <vector> #include <cassert> #include <algorithm> #include "molecules.h" long long sp[200010],ss[200010]; std::vector<int> find_subset(int l, int u, std::vector<int> w) { long long n=w.size(); std::pair<long long,int> v[200010]; for(long long i=0;i<n;++i) v[i+1]={w[i],i}; std::sort(v+1,v+n+1); ss[n+1]=sp[0]=0; for(long long i=1;i<=n;++i) sp[i]=sp[i-1]+v[i].first; long long nrans=n+5; for(long long i=n;i>=1;--i) { ss[i]=ss[i+1]+v[i].first; if(ss[i]>=l&&sp[n-i+1]<=u) nrans=n-i+1; } std::vector<int>ans,ansf; if(nrans==n+5) { return ans; } long long sum=0; for(long long i=1;i<=nrans;++i) { sum+=v[i].first; ans.push_back(v[i].second); } long long i=nrans; while(sum<l) { sum-=w[ans[i-nrans]]; ++i; ans.push_back(v[i].second); sum+=v[i].first; } n=ans.size(); while(nrans) { --n; ansf.push_back(ans[n]); --nrans; } return ansf; } /* int main() { int n, l, u; assert(3 == scanf("%d %d %d", &n, &l, &u)); std::vector<int> w(n); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &w[i])); std::vector<int> result = find_subset(l, u, w); printf("%d\n", (int)result.size()); for (int i = 0; i < (int)result.size(); i++) printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...