Untitled
unknown
plain_text
a year ago
1.1 kB
8
Indexable
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ln '\n'
#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define pb push_back
#define all(x) x.begin(),x.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
string f(ll id, ll k, vll& arr) {
if (k == 0) {
return "";
}
if (k < 0 or id >= n) {
return "0";
}
string a = to_string(id + 1) + f(0, k - arr[id], arr);
string b = f(id + 1, k, arr);
if (a.find("0") != string::npos )return b;
if (b.find("0") != string::npos)return a;
if (a.size() == b.size()) {
return (a[0] > b[0]) ? a : b;
}
return (a.size() > b.size()) ? a : b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll k;
cin >> n >> k;
vll arr(n);
for (auto& it : arr) cin >> it;
cout << f(0, k, arr) << ln;
}Editor is loading...
Leave a Comment