Submission #362342

#TimeUsernameProblemLanguageResultExecution timeMemory
362342usuyusDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms492 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> find_subset(int l, int r, vector<int> a) { int n = a.size(); vector<pair<int,int>> b; for (int i=0; i<n; i++) b.push_back({a[i], i}); sort(a.begin(), a.end()); sort(b.begin(), b.end()); int k; ll s; for (k=s=0; k<n; k++) { if (s+a[k] > l) break; s += a[k]; } if (k == 0) { if (l <= a[0] && a[0] <= r) return {b[0].second}; else return {}; } if (k == n && s < l) return {}; if (l <= s && s <= r) { vector<int> ans; for (int i=0; i<k; i++) ans.push_back(b[i].second); return ans; } for (int i=k-1; i>=0; i--) { s += a[i+n-k] - a[i]; if (l <= s && s <= r) { vector<int> ans; for (int j=0; j<i; j++) ans.push_back(b[j].second); for (int j=i+n-k; j<n; j++) ans.push_back(b[j].second); return ans; } } return {}; }
#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...