Submission #923591

#TimeUsernameProblemLanguageResultExecution timeMemory
923591velislavgarkovDetecting Molecules (IOI16_molecules)C++14
100 / 100
43 ms8788 KiB
#include "molecules.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; const int MAXN=2e5+10; pair <long long, int> a[MAXN]; long long pref[MAXN], n; vector <int> find_subset(int lef, int u, vector <int> w) { n=w.size(); pref[0]=0; for (int i=1;i<=n;i++) { a[i].first=w[i-1]; a[i].second=i-1; } sort(a+1,a+n+1); for (int i=1;i<=n;i++) pref[i]=a[i].first+pref[i-1]; vector <int> ans; for (int i=1;i<=n;i++) { int l, r, mid; l=1; r=i; while (l<=r) { mid=(l+r)/2; if (pref[i]-pref[mid-1]<lef) r=mid-1; else l=mid+1; } if (r>0 && pref[i]-pref[r-1]<=u && pref[i]-pref[r-1]>=lef) { //cout << i << ' ' << r << ' ' << pref[i]-pref[r-1] << endl; for (int j=r;j<=i;j++) ans.push_back(a[j].second); return ans; } } 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...