Submission #987273

#TimeUsernameProblemLanguageResultExecution timeMemory
987273normankr07Detecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms348 KiB
#define taskname "" #include "molecules.h" #include <bits/stdc++.h> using namespace std; using ll = long long; #ifndef LOCAL #define cerr \ if (0) \ cerr #endif const bool multitest = 0; int n, l, u; vector<int> w; std::vector<int> find_subset(int l, int u, std::vector<int> w) { // for (int i = 1; i <= n; i++) // { // if (l <= w[i - 1] && w[i - 1] <= u) // { // return vector<int>(i); // } // } vector<pair<int, int>> ww; ll sum = 0; for (int i = 0; i < n; i++) { sum += w[i]; ww.push_back(make_pair(w[i], i)); } sort(ww.begin(), ww.end()); vector<int> id; for (int i = n - 1, j = n; i < j && i >= -1;) { while (sum > u && i >= 0) { sum -= ww[i].first; i--; } if (l <= sum && sum <= u) { for (int p = 0; p <= i; p++) id.push_back(ww[p].second); for (int p = j; p < n; p++) id.push_back(ww[p].second); return id; } j--; sum += ww[j].first; } return vector<int>(); } void solve() { cin >> n >> l >> u; w.assign(n, 0); for (auto &v : w) cin >> v; auto ans = find_subset(l, u, w); cout << ans.size() << '\n'; for (auto v : ans) { cout << v << ' '; } } /* int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen(taskname ".inp", "r")) { freopen(taskname ".inp", "r", stdin); freopen(taskname ".out", "w", stdout); } int tc = 1; if (multitest) cin >> tc; while (tc--) { solve(); cout << '\n'; } } */
#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...