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;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
const int INF = 1 << 30;
int N, M;
vpii A;
vi B;
vi dp;
vi used;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
A.resize(N);
for (int i = 0; i < N; ++i)
cin >> A[i].first, A[i].second = i;
cin >> M;
B.resize(M);
for (int i = 0; i < M; ++i)
cin >> B[i];
// sort(all(A));
dp.assign(N + 1, INF), used.resize(N + 1);
dp[0] = 0;
for (int i = 1; i < sz(dp); ++i)
for (int b = sz(B) - 1; b >= 0; --b)
if (i - B[b] >= 0 && dp[i] > dp[i - B[b]] + 1)
dp[i] = dp[i - B[b]] + 1, used[i] = b;
if (dp[N] == INF)
{
cout << -1 << "\n";
}
else
{
int i = N;
cout << dp[i] << "\n";
while (i > 0)
{
int b = used[i];
cout << B[b];
for (int j = 0; j < B[b]; ++j)
cout << " " << i--;
cout << "\n";
}
}
return 0;
}
# | 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... |