This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
int f[10009];
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<int>ans;
vector<pii>a;
int n=sz(w);
for1(i,0,n-1)a.pb({w[i],i});
sort(all(a));
if (a[0].fi>u)return {};
for1(i,0,n-1){
if (a[i].fi>=l&&a[i].se<=u){
return {a[i].se};
}
}
for1(i,0,10000){
f[i]=-1;
}
f[0]=0;
for1(i,0,n-1){
for2(j,10000-a[i].fi,0){
if (f[j]!=-1&&f[j+a[i].fi]==-1){
f[j+a[i].fi]=a[i].se;
}
}
}
for1(i,l,u){
if (f[i]!=-1){
vector<int>id;
int value=i;
while (value){
id.pb(f[value]);
value=value-w[f[value]];
}
return id;
}
}
return {};
}
/*signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
int n, l, u;
assert(3 == scanf("%d %d %d", &n, &l, &u));
std::vector<int> w(n);
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &w[i]));
std::vector<int> result = find_subset(l, u, w);
printf("%d\n", (int)result.size());
for (int i = 0; i < (int)result.size(); i++)
printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}*/
# | 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... |