# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
299627 | 2020-09-15T11:08:45 Z | Valee | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include "molecules.h" #include <bits/stdc++.h> #define ll long long using namespace std; vector<int> find_subset(int l, int u, vector<int> v) { bool ok = false; vector<int>ans; int n = (int)v.size(); sort(v.begin(), v.end()); int lb = 0, rb = n+1, lans = 0, rans = 0; while (lb < rb && !ok){ ll m = (lb+rb)>>1, sum = 0; for (int i = 0; i < n; i++){ if (i < m) sum += v[i]; else sum += v[i]-v[i-m]; if (l <= sum && sum <= u){ lans = max(0LL, i-m+1); rans = i; ok = true; break; } } if (sum >= u) rb = m; else lb = m+1; } ll sum = 0; if (ok){ for (int i = lans; i <= rans; i++){ sum += ans[i]; ans.push_back(i); } if (sum < l || sum > r) ans.clear(); } return ans; }