# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1072291 | ivaziva | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
vector<pair<int,int>> vec;
vec.push_back({0,0});
int n=w.size();
for (int i=0;i<n;i++) vec.push_back({w[i],i});
sort(vec.begin(),vec.end());
int l=1,r=1,val=vec[1].first;
bool resenje=false;
while (l<=r)
{
if (val>=l and val<=u) {resenje=true;break;}
if (val<l and r<n) {r++;val+=vec[r].first;}
else if (val<l and r==n) break;
else if (val>u and l<r) {val-=vec[l].first;l++;}
else if (val>u and l==r) break;
}
vector<int> ans;
if (!resenje) return ans;
for (int i=l;i<=r;i++) ans.push_back(vec[i].second);
return ans;
}