Submission #784889

#TimeUsernameProblemLanguageResultExecution timeMemory
784889GusterGoose27Detecting Molecules (IOI16_molecules)C++17
100 / 100
42 ms7116 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = 2e5+5; ll pre[MAXN]; pii arr[MAXN]; int n; ll sum(int l, int r) { return pre[r+1]-pre[l]; } vector<int> find_subset(int l, int r, vector<int> w) { n = w.size(); for (int i = 0; i < n; i++) { arr[i] = pii(w[i], i); } sort(arr, arr+n); for (int i = 1; i <= n; i++) pre[i] = pre[i-1]+arr[i-1].first; for (int i = 0; i < n; i++) { if (sum(0, i) > r || sum(n-i-1, n-1) < l) continue; vector<int> ans; int num = i+1; int incl = 0; for (int j = 0; j < n && num; j++) { assert(j+num <= n); if (incl+sum(j, j+num-1) <= r && incl+arr[j].first+sum(n-num+1, n-1) >= l) { ans.push_back(arr[j].second); incl += arr[j].first; num--; } } assert(l <= incl && incl <= r); return ans; } return vector<int>(); }
#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...