# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1001735 | vjudge1 | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include<bits/stdc++.h>
#pragma GCC optimize("-O3")
#define ll int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
vl find_subset(ll l, ll u, vl w) {
vl ans;
vector<pll>vect;
for(ll i = 0; i < w.size(); i++)
vect.pb({w[i], i});
sort(all(vect));
ll tl = 0, tr = 0, sum = 0;
while(tl < vect.size())
{
while(tr < vect.size() && sum + vect[tr].f <= u)
{
sum += vect[tr].f;
tr++;
if(l <= sum && sum <= u)
{
for(ll j = tl; j < tr; j++)
ans.pb(vect[j].s);
return ans;
}
}
if(l <= sum && sum <= u)
{
for(ll j = tl; j < tr; j++)
ans.pb(vect[j].s);
return ans;
}
sum -= vect[tl].f;
tl++;
}
return ans;
}
int main()
{
int n, l, u;
vi w;
cin >> n >> l >> u;
for(int i = 0; i < n; i++)
{
int x;
cin >> x;
w.pb(x);
}
vi res = find_subset(l, u, w);
for(auto u : res)
cout << u << ' ';
cout << "\n";
}