Submission #228227

#TimeUsernameProblemLanguageResultExecution timeMemory
228227pit4hDetecting Molecules (IOI16_molecules)C++14
100 / 100
69 ms8544 KiB
#include "molecules.h" #include <bits/stdc++.h> #define ll long long #define st first #define nd second using namespace std; vector<int> find_subset(int L, int U, vector<int> W) { ll l = L; ll u = U; vector<pair<ll, int>> w; for(int i=0; i<(int)W.size(); ++i) { w.push_back({W[i], i}); } sort(w.begin(), w.end()); ll sum=0; int n = w.size(), i = 0; vector<int> ans; while(i<n && sum+w[i].st<=u) { sum+=w[i].st; ans.push_back(i); i++; } i = n-1; vector<int> added; while(ans.size() && sum+w[i].st-w[ans.back()].st<=u) { sum+=w[i].st-w[ans.back()].st; added.push_back(i); i--; ans.pop_back(); } if(sum>=l && sum<=u) { for(int k: added) { ans.push_back(k); } for(int &k: ans) { k=w[k].nd; } return ans; } else { return vector<int>(); } }
#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...