Submission #416906

#TimeUsernameProblemLanguageResultExecution timeMemory
416906snasibov05Detecting Molecules (IOI16_molecules)C++14
19 / 100
1 ms204 KiB
#include "molecules.h" #include <algorithm> #include <set> using namespace std; #define pb push_back #define pii pair<int, int> #define f first #define s second vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pii> v(n); for (int i = 0; i < n; ++i) { v[i].f = w[i]; v[i].s = i; } sort(v.begin(), v.end()); set<int> st; int sum = 0; int k = 0; for (int i = n-1; i >= 0; --i){ sum += v[i].f; k = i; st.insert(v[i].s); if (sum >= l) break; } if (sum < l){ vector<int> ans; return ans; } else if (sum >= l && sum <= u){ vector<int> ans; for (auto x : st){ ans.pb(x); } return ans; } for (int i = 0; i < min(k, n/2); ++i){ int dif = v[n-i-1].f - v[i].f; sum -= dif; st.erase(v[n-i-1].s); st.insert(v[i].s); if (sum <= u) break; } if (sum > u){ vector<int> ans; return ans; } else{ vector<int> ans; for (auto x : st){ ans.pb(x); } 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...