# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
305566 | 2020-09-23T14:41:50 Z | tengiz05 | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include "molecules.h" #include "grader.cpp" #include <bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pair<int, int>> a; for(int i=0;i<n;i++){ a.push_back({w[i], i}); } sort(a.begin(), a.end()); vector<int> ans; int sum = 0; for(auto x : w)sum += x; if(sum < l)return ans; sum = 0; int m=0; for(int i=0;i<n;i++){ sum += a[i].first; while(sum > u)sum -= a[m].first, m++; if(sum >= l && sum <= u){ for(int j=m;j<=i;j++)ans.push_back(a[j].second); break; } } // cout << sum << ' '; return ans; } /* 4 15 17 6 8 8 7 4 14 15 5 5 6 6 4 10 20 15 17 16 18 */