# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1265037 | chf | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#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());
long long sum=0;
int l=0;
for(int r=0;r<n;r++)
{
sum+=a[r].first;
while(sum>u&&l<=r)
{
sum-=a[l].first;
l++;
}
if(sum>=l&&sum<=u)
{
vector<int> ans;
for(int i=l;i<=r;i++)ans.push_back(a[i].second);
return ans;
}
}
return {};
}