Submission #1258297

#TimeUsernameProblemLanguageResultExecution timeMemory
1258297sohamsen15Detecting Molecules (IOI16_molecules)C++20
100 / 100
37 ms6172 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> find_subset(int low, int high, vector<int> w) { vector<pair<ll, ll>> a; for (ll i = 0; i < w.size(); i++) a.push_back({ w[i], i }); sort(a.begin(), a.end()); ll l = 0, r = 0, n = a.size(), s = a[0].first; bool done = false; while (r < n) { if (s >= low && s <= high) { done = true; break; } if (s > high) s -= a[l].first, l++; else r++, s += a[r].first; } if (!done) return vector<int>(0); vector<int> ans; for (ll i = l; i <= r; i++) ans.push_back(a[i].second); sort(ans.begin(), ans.end()); return ans; } // int main() { // vector<int> ans = find_subset(10, 20, {15, 17, 16, 18}); // for (auto x: ans) cout << x << " "; // }

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...