#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
/*pair<vector<int>,bool> solve(int l,int u,vector<pair<int,int>>& W){
if(l <= 0)
return {{},true};
vector<int> ans;
bool ok = false;
for(int i=0;i<W.size();i++){
if(W[i].first > u || take[i])
continue;
take[i] = true;
auto res = solve(l-W[i].first,u-W[i].first,W);
ans = res.first;
ans.push_back(W[i].second);
ok = res.second;
if(ok){
break;
}
else
ans = vector<int>();
take[i] = false;
}
return {ans,ok};
}*/
/*vector<int> solve(int l,int u,vector<int>& w){
vector<bool> dp(1e6+1,false);
dp[0] = true;
int n = w.size();
for(int i=0;i<n;i++){
for(int j=1e6;j>=0;j--){
if(j+w[i] <= 1e6 && dp[j]){
dp[j+w[i]] = true;
}
}
}
vector<int> ans;
for(int i=l;i<=u;i++){
if(dp[i]){
vector<int> take(n,false);
for(int j=0;j<n;j++){
if(i-w[j] >= 0){
if(dp[i-w[j]] && !take[j]){
ans.push_back(j);
take[j] = true;
i-=w[j];
j = 0;
}
}
}
break;
}
}
return ans;
}*/
vector<int> find_subset(int l, int u,vector<int> w) {
int n = w.size();
vector<pair<int,int>> W(n);
for(int i=0;i<n;i++){
W[i].first = w[i];
W[i].second = i;
}
sort(W.begin(),W.end());
long long sum = 0;
int L=0,R=0;
deque<int> dq;
while(R < n && L < n && L<=R){
if(sum < l){
sum += W[R].first;
dq.push_back(W[R].second);
R++;
}
else if(sum > u){
sum -= W[L].first;
dq.pop_front();
L++;
}
else
break;
}
vector<int> ans;
for(int i=0;i<dq.size();i++){
ans.push_back(dq[i]);
}
return ans;
}
Compilation message (stderr)
molecules.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |