#include <bits/stdc++.h>
using namespace std;
struct cookieType {
int count, type;
};
const int MAX_N = 15000;
const int MAX_M = 15000;
cookieType cookies[MAX_N];
int boxsize[MAX_M];
vector<int> cookiesByBox[MAX_N];
int main() {
int n, m;
cin >> n;
for ( int i = 0; i < n; i++ ) {
cin >> cookies[i].count;
cookies[i].type = i + 1;
}
cin >> m;
for ( int i = 0; i < m; i++ )
cin >> boxsize[i];
int sumCookies = 0, maxCookies = 0;
for ( int i = 0; i < n; i++ ) {
sumCookies += cookies[i].count;
maxCookies = max( maxCookies, cookies[i].count );
}
int bs = boxsize[0];
if ( sumCookies % bs != 0 || maxCookies > sumCookies / bs ) {
cout << -1;
return 0;
}
sort( cookies, cookies + n, []( cookieType x, cookieType y ) {
return x.count > y.count;
} );
int b = sumCookies / bs, j = 0;
for ( int i = 0; i < n; i++ ) {
while ( cookies[i].count > 0 ) {
cookiesByBox[j].push_back( cookies[i].type );
j = (j + 1) % b;
cookies[i].count--;
}
}
cout << b << "\n";
for ( int i = 0; i < b; i++ ) {
cout << bs << " ";
for ( int j: cookiesByBox[i] )
cout << j << " ";
cout << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
796 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
944 KB |
Output is correct |
19 |
Correct |
3 ms |
1112 KB |
Output is correct |
20 |
Correct |
2 ms |
1112 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |