Submission #967240

#TimeUsernameProblemLanguageResultExecution timeMemory
967240huutuanCookies (JOI23_cookies)C++14
7 / 100
3 ms1432 KiB
#include<bits/stdc++.h> using namespace std; const int N=15e3+10; bool f[N][N]; int n, m, a[N], b[N]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i=1; i<=n; ++i) cin >> a[i]; cin >> m; for (int i=1; i<=m; ++i) cin >> b[i]; reverse(b+1, b+m+1); int sum=accumulate(a+1, a+n+1, 0); f[0][0]=1; for (int i=1; i<=m; ++i){ memcpy(f[i], f[i-1], sizeof f[i]); for (int j=b[i]; j<=sum; ++j) f[i][j]|=f[i][j-b[i]]; } if (!f[m][sum]){ cout << -1 << '\n'; return 0; } vector<int> sz; for (int i=m; i>=1; --i){ for (int j=sum/b[i]; j>=0; --j) if (f[i-1][sum-j*b[i]]){ while (j--) sz.push_back(b[i]), sum-=b[i]; } } priority_queue<pair<int, int>> pq; for (int i=1; i<=n; ++i) pq.emplace(a[i], i); vector<vector<int>> ans; for (int i:sz){ ans.emplace_back(); for (int j=0; j<i; ++j){ if (pq.empty()){ cout << -1 << '\n'; return 0; } ans.back().push_back(pq.top().second); pq.pop(); } for (int j:ans.back()){ --a[j]; if (a[j]) pq.emplace(a[j], j); } } cout << ans.size() << '\n'; for (auto &i:ans){ cout << i.size(); for (int j:i) cout << ' ' << j; 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...