Submission #829236

#TimeUsernameProblemLanguageResultExecution timeMemory
829236HanksburgerCookies (JOI23_cookies)C++17
6 / 100
3 ms340 KiB
#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 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...