This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
1 5
0 0 6
*/
#pragma GCC optimize ("O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int M;
ll L;
cin >> M >> L;
ll A[2 * M + 1];
for (int i = 0; i <= 2 * M; i++)
cin >> A[i];
L = -L;
ll cnt = 0;
for (int l = -M; l <= M; l++)
{
L += l * A[l + M];
cnt += A[l + M];
}
map<ll, ll>D;
D[0] = 0;
for (int l = -M; l <= M; l++)
{
map<ll, ll>D_;
for (pair<ll, ll>v : D)
{
for (int c = 0; c <= A[l + M]; c++)
{
ll v_ = v.first + l * c;
ll c_ = v.second + c;
if (D_.count(v_) == 0)
D_[v_] = c_;
else
D_[v_] = min(D_[v_], c_);
}
}
D = D_;
}
if (D.count(L))
cout << cnt - D[L] << "\n";
else
cout << "impossible\n";
}
# | 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... |
# | 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... |