This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |