Submission #362836

#TimeUsernameProblemLanguageResultExecution timeMemory
362836saarthakDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms384 KiB
#include <bits/stdc++.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, a = 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); int i = 0, j = 0; while(i < n || j < n) { if(total_weight < l) { total_weight += wts[j].wt; indices.push(wts[j++].idx); if(j >= n) break; } else if(total_weight > u) { total_weight -= wts[i++].wt; indices.pop(); if(i >= n) break; } else break; } if(total_weight < l || total_weight > u) return std::vector<int>(); //no subarray found std::vector<int> ans(indices.size()); while(!indices.empty()) { ans[a++] = 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...