#include <bits/stdc++.h>
using namespace std;
const int Nmax=510;
int N, M, tot, mx, ans, A[Nmax], B[Nmax], X[Nmax];
vector<int> Y[Nmax];
vector<pair<int, int>> V, W;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N;
for(int i=1; i<=N; i++) cin>>A[i], tot+=A[i], mx=max(mx, A[i]);
cin>>M;
for(int i=1; i<=M; i++) cin>>B[i];
if(tot%B[1] || (tot/B[1])<mx) {
cout<<-1; return 0;
}
ans=tot/B[1];
for(int i=0; i<ans; i++) X[i]=B[1], V.push_back({B[1], i});
for(int i=1; i<=N; i++) W.push_back({A[i], i});
sort(W.rbegin(), W.rend());
for(int i=0; i<N; i++) {
sort(V.rbegin(), V.rend());
for(int j=0; j<(rand()%N); j++) next_permutation(V.begin(), V.end());
int cnt=0;
for(int j=0; j<ans; j++) {
if(V[j].first==0) continue;
cnt++, V[j].first--, Y[V[j].second].push_back(W[i].second);
if(cnt>=W[i].first) break;
}
if(cnt<W[i].first) {
cout<<-1; return 0;
}
}
cout<<ans<<"\n";
for(int i=0; i<ans; i++) {
cout<<X[i]<<" ";
for(int j:Y[i]) cout<<j<<" ";
cout<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Unexpected end of file - int32 expected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |