#include<bits/stdc++.h>
#define MAXN 507
using namespace std;
int n,m,pt,total;
int a[MAXN],b[MAXN];
vector< pair<int,int> > v;
vector< vector<int> > w;
int maxs[MAXN],br;
bool li[MAXN][MAXN][MAXN];
int dp[MAXN][MAXN][MAXN];
int ff(int pos,int box,int sum){
if(sum<0 or box<1)return 1000000;
if(sum==0)return 0;
if(li[pos][box][sum])return dp[pos][box][sum];
li[pos][box][sum]=true;
dp[pos][box][sum]=ff(pos,box-1,sum);
if(total-sum+b[box]<=maxs[pos]){
dp[pos][box][sum]=min(dp[pos][box][sum],ff(pos+1,box,sum-b[box])+1);
}
return dp[pos][box][sum];
}
void solve(int pos,int box,int sum){
if(box<1 or sum<0){
cout<<1/0;
exit(0);
}
if(sum==0)return;
if(ff(pos,box,sum)==ff(pos,box-1,sum)){
solve(pos,box-1,sum); return;
}
br++; v.push_back({b[box],br});
solve(pos+1,box,sum-b[box]);
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
total+=a[i];
}
for(int i=1;i<=total;i++){
for(int f=1;f<=n;f++){
maxs[i]+=min(a[f],i);
}
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>b[i];
}
if(ff(1,m,total)>total){
cout<<"-1\n";
}
solve(1,m,total);
w.resize(int(v.size()));
sort(a+1,a+n+1);
reverse(a+1,a+n+1);
for(int i=1;i<=n;i++){
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(int f=0;f<a[i];f++){
v[f].first--;
w[v[f].second-1].push_back(i);
}
}
cout<<w.size()<<"\n";
for(int i=0;i<w.size();i++){
cout<<w[i].size()<<" ";
for(int f:w[i])cout<<f<<" ";
cout<<"\n";
}
return 0;
}
Compilation message
cookies.cpp: In function 'void solve(int, int, int)':
cookies.cpp:33:16: warning: division by zero [-Wdiv-by-zero]
33 | cout<<1/0;
| ~^~
cookies.cpp: In function 'int main()':
cookies.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i=0;i<w.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
44 ms |
395176 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
50 ms |
403048 KB |
Output is correct |
11 |
Runtime error |
16 ms |
9364 KB |
Execution killed with signal 4 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
8796 KB |
Execution killed with signal 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Runtime error |
16 ms |
8796 KB |
Execution killed with signal 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
44 ms |
395176 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
50 ms |
403048 KB |
Output is correct |
11 |
Runtime error |
16 ms |
9364 KB |
Execution killed with signal 4 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
44 ms |
395176 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
50 ms |
403048 KB |
Output is correct |
11 |
Runtime error |
16 ms |
9364 KB |
Execution killed with signal 4 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
44 ms |
395176 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
50 ms |
403048 KB |
Output is correct |
11 |
Runtime error |
16 ms |
9364 KB |
Execution killed with signal 4 |
12 |
Halted |
0 ms |
0 KB |
- |