# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501449 | MurotY | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
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>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll int
#define ff first
#define ss second
using namespace std;
const int N=1e6+7;
ll a[N], b[N], sum=0;
bool dp[N];
vector <ll> v[N];
ll mp[N], mp1[N];
bool knapSack(ll n, ll k){
memset(dp, 0, sizeof(dp));
dp[0]=1;
for (int i=1;i<=900;i++) v[i].push_back(i);
for (int i=1;i<=n;i++){
for (int j=sum;j>=0;j--){
if (a[i]+j <= sum and dp[a[i]+j] == 0) {
dp[a[i]+j] |= dp[j];
if (dp[a[i]+j] and mp[a[i]+j] == 0) {
for (auto it:v[j]) v[j+a[i]].push_back(it);
if (j != 0) for (auto it:v[a[i]]) v[j+a[i]].push_back(it);
}
}
}
}
/* cout << dp[k] <<" ";
for (int i=1;i<=11;i++) {
for (auto it:v[i]) cout << it <<" ";
cout <<"\n";
}*/
return dp[k];
}
int main()
{
ll n, k;
cin >> n >> k;
for (int i=1;i<=n;i++) cin >> a[i], sum+=a[i], mp[a[i]]++, mp1[a[i]]=i;
sort(a+1,a+n+1);
if (knapSack(n, k) == 0) cout << "no";
else {
for (auto it:v[k]) if (mp1[it] > 0) cout << mp1[it]-1 <<" ";
}
}