Submission #330268

#TimeUsernameProblemLanguageResultExecution timeMemory
330268saarthakDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms384 KiB
#include <bits/stdc++.h> #include "molecules.h" struct weights { int wt; int idx; }; bool cmp(weights a, weights b) { return (a.wt < b.wt); } std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); int total_weight = 0, i = 0; std::queue<int> indices; std::vector<struct weights> wts(n); for(int i = 0; i < n; i++) wts[i] = {w[i], i}; std::sort(wts.begin(), wts.end(), cmp); while(total_weight < l && i < n) { total_weight += wts[i].wt; indices.push(wts[i++].idx); } i = 0; while(total_weight > u && i < n) { total_weight -= wts[i++].wt; indices.pop(); } if(total_weight < l || total_weight > u) return std::vector<int>(); //no subarray found std::vector<int> ans(indices.size()); i = 0; while(!indices.empty()) { ans[i++] = indices.front(); indices.pop(); } 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...