# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
775533 | aguss | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<pair<int, int>> v(n);
vector<int> ans;
for(int i = 0; i < n; i++){
v[i].first = w[i];
v[i].second = i;
}
sort(v.begin(), v.end());
ll sum = v[0].first, s = 0, e = 0;
while(e < n and s < n){
if(sum >= l and sum <= u){
for(int i = s; i <= e; i++)
ans.push_back(v[i].second);
return ans;
}
if(sum < l)
sum += v[++e].first;
if(sum > u)
sum -= v[s++].first;
}
return vector<int>(0);
}
int main(){
int l, u, n;
cin >> l >> u >> n;
vector<int> arr(n);
for(int &i : arr) cin >> i;
vector<int> ans = find_subset(l, u, arr);
for(int i : ans) cout << i << " ";
return 0;
}