Submission #796338

#TimeUsernameProblemLanguageResultExecution timeMemory
796338JohannCookies (JOI23_cookies)C++14
0 / 100
1 ms212 KiB
#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() 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, INT_MAX), 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; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...