Submission #394533

#TimeUsernameProblemLanguageResultExecution timeMemory
394533ruadhanDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms208 KiB
#include <bits/stdc++.h> typedef long long ll; #define sz(x) (int)x.size() using namespace std; typedef pair<int, int> pi; vector<int> find_subset(int l, int u, vector<int> ww) { int n = sz(ww); vector<pair<int, int>> w; for (int i = 0; i < (int)ww.size(); i++) { w.push_back({ww[i], i}); } sort(w.begin(), w.end()); // for (auto x : w) // cout << x.first << " "; // cout << '\n'; int i = 0, j = 0; ll sum = w[0].first; while (j < n) { // cout << "i = " << i << ", j = " << j << '\n'; // cout << "sum = " << sum << '\n'; while (j + 1 < n && sum < l) { j++; sum += w[j].first; } // if (j == n - 1 && i == n - 2) // break; while (i + 1 < n && i + 1 <= j && sum > u) { sum -= w[i].first; i++; } if (sum >= l && sum <= u) break; j++; } vector<int> ans; if (sum >= l && sum <= u) { for (int k = i; k <= j; k++) { ans.push_back(k); } } return ans; } // int main() // { // // auto ret = find_subset(15, 17, {6, 8, 8, 7}); // // auto ret = find_subset(14, 15, {5, 5, 6, 6}); // auto ret = find_subset(10, 20, {15, 17, 16, 18}); // for (auto x : ret) // cout // << x << " "; // cout << '\n'; // return 0; // }
#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...