Submission #411568

#TimeUsernameProblemLanguageResultExecution timeMemory
411568nxteruDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms292 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; using ll=long long; vector<int> find_subset(int L, int U, std::vector<int> W) { ll l=L,u=U; ll n=W.size(); vector<pair<ll,ll>>w(n); for(int i=0;i<n;i++)w[i]=make_pair(W[i],i); sort(w.begin(),w.end()); vector<ll>s(n),t(n); for(int i=0;i<n;i++){ s[i]=w[i].first; if(i>0)s[i]+=s[i-1]; } for(int i=n-1;i>=0;i--){ t[i]=w[i].first; if(i+1<=n-1)t[i]+=t[i+1]; } vector<int>ans; int p=0; for(int i=0;i<=n;i++){ ll ss=0; if(i>0)ss+=s[i-1]; while(p<n&&ss+t[p]>u)p++; if(p<n)ss+=t[p]; if(l<=ss&&ss<=u){ for(int j=0;j<i;j++)ans.push_back(w[j].second); for(int j=p;j<n;j++)ans.push_back(w[j].second); break; } } return ans; }
#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...