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;
int a[15005], b[15005], dp[505], pre[505];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
for (int i=1; i<=n; i++)
cin >> a[i];
cin >> m;
for (int i=1; i<=m; i++)
cin >> b[i];
for (int i=1; i<=n; i++)
{
dp[i]=1e9;
for (int j=1; j<=m; j++)
{
if (i>=b[j])
{
if (dp[i]>dp[i-b[j]]+1)
{
dp[i]=dp[i-b[j]]+1;
pre[i]=i-b[j];
}
}
}
}
if (dp[n]<5e8)
{
cout << dp[n] << '\n';
int ind=n, cnt=0;
while (ind)
{
cout << ind-pre[ind] << ' ';
for (int i=cnt+1; i<=cnt+ind-pre[ind]; i++)
cout << i << ' ';
cout << '\n';
cnt+=ind-pre[ind];
ind=pre[ind];
}
}
else
cout << -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... |