#include<bits/stdc++.h>
#define MAXN 3007
using namespace std;
int n,m,pt,total;
int a[MAXN],b[MAXN],ind[MAXN];
vector< pair<int,int> > v;
vector< vector<int> > w;
int maxs[MAXN],br;
unordered_map<int,int> dp[MAXN][MAXN];
int ff(int pos,int box,int sum){
if(sum<0 or box<1)return 1000000;
if(sum==0)return 0;
if(dp[box][sum][pos]!=0)return dp[box][sum][pos];
dp[box][sum][pos]=ff(pos,box-1,sum);
if(total-sum+b[box]<=maxs[pos]){
dp[box][sum][pos]=min(dp[box][sum][pos],ff(pos+1,box,sum-b[box])+1);
}
return dp[box][sum][pos];
}
void solve(int pos,int box,int sum){
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]);
}
bool cmp(int x,int y){
return a[x]>a[y];
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
total+=a[i];
ind[i]=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";
return 0;
}
solve(1,m,total);
w.resize(int(v.size()));
sort(ind+1,ind+n+1,cmp);
for(int i=1;i<=n;i++){
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(int f=0;f<a[ind[i]];f++){
v[f].first--;
w[v[f].second-1].push_back(ind[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 'int main()':
cookies.cpp:85:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=0;i<w.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
495696 KB |
Output is correct |
2 |
Correct |
140 ms |
495696 KB |
Output is correct |
3 |
Correct |
150 ms |
496320 KB |
Output is correct |
4 |
Correct |
135 ms |
495700 KB |
Output is correct |
5 |
Correct |
137 ms |
495960 KB |
Output is correct |
6 |
Correct |
134 ms |
495676 KB |
Output is correct |
7 |
Correct |
143 ms |
495740 KB |
Output is correct |
8 |
Correct |
137 ms |
495824 KB |
Output is correct |
9 |
Correct |
148 ms |
495712 KB |
Output is correct |
10 |
Correct |
286 ms |
537156 KB |
Output is correct |
11 |
Correct |
143 ms |
500308 KB |
Output is correct |
12 |
Correct |
185 ms |
509780 KB |
Output is correct |
13 |
Correct |
138 ms |
497236 KB |
Output is correct |
14 |
Correct |
144 ms |
500048 KB |
Output is correct |
15 |
Correct |
142 ms |
499540 KB |
Output is correct |
16 |
Correct |
145 ms |
500404 KB |
Output is correct |
17 |
Correct |
136 ms |
495964 KB |
Output is correct |
18 |
Correct |
142 ms |
499016 KB |
Output is correct |
19 |
Correct |
133 ms |
496236 KB |
Output is correct |
20 |
Correct |
131 ms |
495708 KB |
Output is correct |
21 |
Correct |
152 ms |
499792 KB |
Output is correct |
22 |
Correct |
160 ms |
505168 KB |
Output is correct |
23 |
Correct |
157 ms |
503892 KB |
Output is correct |
24 |
Correct |
138 ms |
497748 KB |
Output is correct |
25 |
Correct |
136 ms |
497656 KB |
Output is correct |
26 |
Correct |
132 ms |
496224 KB |
Output is correct |
27 |
Correct |
131 ms |
495960 KB |
Output is correct |
28 |
Correct |
141 ms |
497768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
495916 KB |
Output is correct |
2 |
Correct |
130 ms |
495788 KB |
Output is correct |
3 |
Correct |
130 ms |
495888 KB |
Output is correct |
4 |
Correct |
132 ms |
495888 KB |
Output is correct |
5 |
Correct |
136 ms |
495952 KB |
Output is correct |
6 |
Correct |
130 ms |
495696 KB |
Output is correct |
7 |
Correct |
134 ms |
495844 KB |
Output is correct |
8 |
Correct |
132 ms |
495956 KB |
Output is correct |
9 |
Correct |
136 ms |
496556 KB |
Output is correct |
10 |
Runtime error |
538 ms |
1005380 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
495792 KB |
Output is correct |
2 |
Correct |
135 ms |
495704 KB |
Output is correct |
3 |
Correct |
135 ms |
495888 KB |
Output is correct |
4 |
Correct |
137 ms |
495696 KB |
Output is correct |
5 |
Correct |
138 ms |
495688 KB |
Output is correct |
6 |
Correct |
140 ms |
495696 KB |
Output is correct |
7 |
Correct |
140 ms |
495696 KB |
Output is correct |
8 |
Correct |
135 ms |
495892 KB |
Output is correct |
9 |
Correct |
136 ms |
495704 KB |
Output is correct |
10 |
Correct |
135 ms |
495700 KB |
Output is correct |
11 |
Correct |
135 ms |
495700 KB |
Output is correct |
12 |
Correct |
138 ms |
495700 KB |
Output is correct |
13 |
Correct |
135 ms |
495696 KB |
Output is correct |
14 |
Correct |
135 ms |
495836 KB |
Output is correct |
15 |
Correct |
136 ms |
495804 KB |
Output is correct |
16 |
Correct |
135 ms |
495868 KB |
Output is correct |
17 |
Correct |
138 ms |
495724 KB |
Output is correct |
18 |
Correct |
136 ms |
495696 KB |
Output is correct |
19 |
Correct |
134 ms |
495852 KB |
Output is correct |
20 |
Correct |
135 ms |
495700 KB |
Output is correct |
21 |
Correct |
135 ms |
495696 KB |
Output is correct |
22 |
Correct |
135 ms |
495704 KB |
Output is correct |
23 |
Correct |
136 ms |
495712 KB |
Output is correct |
24 |
Correct |
134 ms |
495704 KB |
Output is correct |
25 |
Correct |
134 ms |
495648 KB |
Output is correct |
26 |
Correct |
139 ms |
495896 KB |
Output is correct |
27 |
Correct |
137 ms |
495680 KB |
Output is correct |
28 |
Correct |
135 ms |
495696 KB |
Output is correct |
29 |
Correct |
138 ms |
495896 KB |
Output is correct |
30 |
Correct |
135 ms |
495696 KB |
Output is correct |
31 |
Correct |
134 ms |
495888 KB |
Output is correct |
32 |
Correct |
134 ms |
495796 KB |
Output is correct |
33 |
Correct |
135 ms |
495696 KB |
Output is correct |
34 |
Correct |
134 ms |
495700 KB |
Output is correct |
35 |
Correct |
133 ms |
495708 KB |
Output is correct |
36 |
Correct |
134 ms |
495700 KB |
Output is correct |
37 |
Correct |
141 ms |
495828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
495696 KB |
Output is correct |
2 |
Correct |
140 ms |
495696 KB |
Output is correct |
3 |
Correct |
150 ms |
496320 KB |
Output is correct |
4 |
Correct |
135 ms |
495700 KB |
Output is correct |
5 |
Correct |
137 ms |
495960 KB |
Output is correct |
6 |
Correct |
134 ms |
495676 KB |
Output is correct |
7 |
Correct |
143 ms |
495740 KB |
Output is correct |
8 |
Correct |
137 ms |
495824 KB |
Output is correct |
9 |
Correct |
148 ms |
495712 KB |
Output is correct |
10 |
Correct |
286 ms |
537156 KB |
Output is correct |
11 |
Correct |
143 ms |
500308 KB |
Output is correct |
12 |
Correct |
185 ms |
509780 KB |
Output is correct |
13 |
Correct |
138 ms |
497236 KB |
Output is correct |
14 |
Correct |
144 ms |
500048 KB |
Output is correct |
15 |
Correct |
142 ms |
499540 KB |
Output is correct |
16 |
Correct |
145 ms |
500404 KB |
Output is correct |
17 |
Correct |
136 ms |
495964 KB |
Output is correct |
18 |
Correct |
142 ms |
499016 KB |
Output is correct |
19 |
Correct |
133 ms |
496236 KB |
Output is correct |
20 |
Correct |
131 ms |
495708 KB |
Output is correct |
21 |
Correct |
152 ms |
499792 KB |
Output is correct |
22 |
Correct |
160 ms |
505168 KB |
Output is correct |
23 |
Correct |
157 ms |
503892 KB |
Output is correct |
24 |
Correct |
138 ms |
497748 KB |
Output is correct |
25 |
Correct |
136 ms |
497656 KB |
Output is correct |
26 |
Correct |
132 ms |
496224 KB |
Output is correct |
27 |
Correct |
131 ms |
495960 KB |
Output is correct |
28 |
Correct |
141 ms |
497768 KB |
Output is correct |
29 |
Correct |
138 ms |
495792 KB |
Output is correct |
30 |
Correct |
135 ms |
495704 KB |
Output is correct |
31 |
Correct |
135 ms |
495888 KB |
Output is correct |
32 |
Correct |
137 ms |
495696 KB |
Output is correct |
33 |
Correct |
138 ms |
495688 KB |
Output is correct |
34 |
Correct |
140 ms |
495696 KB |
Output is correct |
35 |
Correct |
140 ms |
495696 KB |
Output is correct |
36 |
Correct |
135 ms |
495892 KB |
Output is correct |
37 |
Correct |
136 ms |
495704 KB |
Output is correct |
38 |
Correct |
135 ms |
495700 KB |
Output is correct |
39 |
Correct |
135 ms |
495700 KB |
Output is correct |
40 |
Correct |
138 ms |
495700 KB |
Output is correct |
41 |
Correct |
135 ms |
495696 KB |
Output is correct |
42 |
Correct |
135 ms |
495836 KB |
Output is correct |
43 |
Correct |
136 ms |
495804 KB |
Output is correct |
44 |
Correct |
135 ms |
495868 KB |
Output is correct |
45 |
Correct |
138 ms |
495724 KB |
Output is correct |
46 |
Correct |
136 ms |
495696 KB |
Output is correct |
47 |
Correct |
134 ms |
495852 KB |
Output is correct |
48 |
Correct |
135 ms |
495700 KB |
Output is correct |
49 |
Correct |
135 ms |
495696 KB |
Output is correct |
50 |
Correct |
135 ms |
495704 KB |
Output is correct |
51 |
Correct |
136 ms |
495712 KB |
Output is correct |
52 |
Correct |
134 ms |
495704 KB |
Output is correct |
53 |
Correct |
134 ms |
495648 KB |
Output is correct |
54 |
Correct |
139 ms |
495896 KB |
Output is correct |
55 |
Correct |
137 ms |
495680 KB |
Output is correct |
56 |
Correct |
135 ms |
495696 KB |
Output is correct |
57 |
Correct |
138 ms |
495896 KB |
Output is correct |
58 |
Correct |
135 ms |
495696 KB |
Output is correct |
59 |
Correct |
134 ms |
495888 KB |
Output is correct |
60 |
Correct |
134 ms |
495796 KB |
Output is correct |
61 |
Correct |
135 ms |
495696 KB |
Output is correct |
62 |
Correct |
134 ms |
495700 KB |
Output is correct |
63 |
Correct |
133 ms |
495708 KB |
Output is correct |
64 |
Correct |
134 ms |
495700 KB |
Output is correct |
65 |
Correct |
141 ms |
495828 KB |
Output is correct |
66 |
Correct |
134 ms |
495688 KB |
Output is correct |
67 |
Correct |
137 ms |
495956 KB |
Output is correct |
68 |
Correct |
134 ms |
495696 KB |
Output is correct |
69 |
Correct |
134 ms |
495700 KB |
Output is correct |
70 |
Correct |
140 ms |
496340 KB |
Output is correct |
71 |
Correct |
155 ms |
503260 KB |
Output is correct |
72 |
Correct |
138 ms |
497488 KB |
Output is correct |
73 |
Correct |
133 ms |
495952 KB |
Output is correct |
74 |
Correct |
137 ms |
496212 KB |
Output is correct |
75 |
Correct |
150 ms |
501356 KB |
Output is correct |
76 |
Correct |
155 ms |
501332 KB |
Output is correct |
77 |
Correct |
153 ms |
503424 KB |
Output is correct |
78 |
Correct |
150 ms |
500816 KB |
Output is correct |
79 |
Correct |
151 ms |
501332 KB |
Output is correct |
80 |
Correct |
148 ms |
501548 KB |
Output is correct |
81 |
Correct |
136 ms |
496752 KB |
Output is correct |
82 |
Correct |
161 ms |
504656 KB |
Output is correct |
83 |
Correct |
137 ms |
496032 KB |
Output is correct |
84 |
Correct |
170 ms |
506704 KB |
Output is correct |
85 |
Correct |
155 ms |
502100 KB |
Output is correct |
86 |
Correct |
187 ms |
510800 KB |
Output is correct |
87 |
Correct |
180 ms |
509372 KB |
Output is correct |
88 |
Correct |
185 ms |
510036 KB |
Output is correct |
89 |
Correct |
196 ms |
511928 KB |
Output is correct |
90 |
Correct |
178 ms |
509008 KB |
Output is correct |
91 |
Correct |
181 ms |
509212 KB |
Output is correct |
92 |
Correct |
200 ms |
512392 KB |
Output is correct |
93 |
Correct |
201 ms |
517056 KB |
Output is correct |
94 |
Correct |
175 ms |
507800 KB |
Output is correct |
95 |
Correct |
175 ms |
507984 KB |
Output is correct |
96 |
Correct |
155 ms |
502608 KB |
Output is correct |
97 |
Correct |
154 ms |
502876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
495696 KB |
Output is correct |
2 |
Correct |
140 ms |
495696 KB |
Output is correct |
3 |
Correct |
150 ms |
496320 KB |
Output is correct |
4 |
Correct |
135 ms |
495700 KB |
Output is correct |
5 |
Correct |
137 ms |
495960 KB |
Output is correct |
6 |
Correct |
134 ms |
495676 KB |
Output is correct |
7 |
Correct |
143 ms |
495740 KB |
Output is correct |
8 |
Correct |
137 ms |
495824 KB |
Output is correct |
9 |
Correct |
148 ms |
495712 KB |
Output is correct |
10 |
Correct |
286 ms |
537156 KB |
Output is correct |
11 |
Correct |
143 ms |
500308 KB |
Output is correct |
12 |
Correct |
185 ms |
509780 KB |
Output is correct |
13 |
Correct |
138 ms |
497236 KB |
Output is correct |
14 |
Correct |
144 ms |
500048 KB |
Output is correct |
15 |
Correct |
142 ms |
499540 KB |
Output is correct |
16 |
Correct |
145 ms |
500404 KB |
Output is correct |
17 |
Correct |
136 ms |
495964 KB |
Output is correct |
18 |
Correct |
142 ms |
499016 KB |
Output is correct |
19 |
Correct |
133 ms |
496236 KB |
Output is correct |
20 |
Correct |
131 ms |
495708 KB |
Output is correct |
21 |
Correct |
152 ms |
499792 KB |
Output is correct |
22 |
Correct |
160 ms |
505168 KB |
Output is correct |
23 |
Correct |
157 ms |
503892 KB |
Output is correct |
24 |
Correct |
138 ms |
497748 KB |
Output is correct |
25 |
Correct |
136 ms |
497656 KB |
Output is correct |
26 |
Correct |
132 ms |
496224 KB |
Output is correct |
27 |
Correct |
131 ms |
495960 KB |
Output is correct |
28 |
Correct |
141 ms |
497768 KB |
Output is correct |
29 |
Correct |
138 ms |
495792 KB |
Output is correct |
30 |
Correct |
135 ms |
495704 KB |
Output is correct |
31 |
Correct |
135 ms |
495888 KB |
Output is correct |
32 |
Correct |
137 ms |
495696 KB |
Output is correct |
33 |
Correct |
138 ms |
495688 KB |
Output is correct |
34 |
Correct |
140 ms |
495696 KB |
Output is correct |
35 |
Correct |
140 ms |
495696 KB |
Output is correct |
36 |
Correct |
135 ms |
495892 KB |
Output is correct |
37 |
Correct |
136 ms |
495704 KB |
Output is correct |
38 |
Correct |
135 ms |
495700 KB |
Output is correct |
39 |
Correct |
135 ms |
495700 KB |
Output is correct |
40 |
Correct |
138 ms |
495700 KB |
Output is correct |
41 |
Correct |
135 ms |
495696 KB |
Output is correct |
42 |
Correct |
135 ms |
495836 KB |
Output is correct |
43 |
Correct |
136 ms |
495804 KB |
Output is correct |
44 |
Correct |
135 ms |
495868 KB |
Output is correct |
45 |
Correct |
138 ms |
495724 KB |
Output is correct |
46 |
Correct |
136 ms |
495696 KB |
Output is correct |
47 |
Correct |
134 ms |
495852 KB |
Output is correct |
48 |
Correct |
135 ms |
495700 KB |
Output is correct |
49 |
Correct |
135 ms |
495696 KB |
Output is correct |
50 |
Correct |
135 ms |
495704 KB |
Output is correct |
51 |
Correct |
136 ms |
495712 KB |
Output is correct |
52 |
Correct |
134 ms |
495704 KB |
Output is correct |
53 |
Correct |
134 ms |
495648 KB |
Output is correct |
54 |
Correct |
139 ms |
495896 KB |
Output is correct |
55 |
Correct |
137 ms |
495680 KB |
Output is correct |
56 |
Correct |
135 ms |
495696 KB |
Output is correct |
57 |
Correct |
138 ms |
495896 KB |
Output is correct |
58 |
Correct |
135 ms |
495696 KB |
Output is correct |
59 |
Correct |
134 ms |
495888 KB |
Output is correct |
60 |
Correct |
134 ms |
495796 KB |
Output is correct |
61 |
Correct |
135 ms |
495696 KB |
Output is correct |
62 |
Correct |
134 ms |
495700 KB |
Output is correct |
63 |
Correct |
133 ms |
495708 KB |
Output is correct |
64 |
Correct |
134 ms |
495700 KB |
Output is correct |
65 |
Correct |
141 ms |
495828 KB |
Output is correct |
66 |
Correct |
134 ms |
495688 KB |
Output is correct |
67 |
Correct |
137 ms |
495956 KB |
Output is correct |
68 |
Correct |
134 ms |
495696 KB |
Output is correct |
69 |
Correct |
134 ms |
495700 KB |
Output is correct |
70 |
Correct |
140 ms |
496340 KB |
Output is correct |
71 |
Correct |
155 ms |
503260 KB |
Output is correct |
72 |
Correct |
138 ms |
497488 KB |
Output is correct |
73 |
Correct |
133 ms |
495952 KB |
Output is correct |
74 |
Correct |
137 ms |
496212 KB |
Output is correct |
75 |
Correct |
150 ms |
501356 KB |
Output is correct |
76 |
Correct |
155 ms |
501332 KB |
Output is correct |
77 |
Correct |
153 ms |
503424 KB |
Output is correct |
78 |
Correct |
150 ms |
500816 KB |
Output is correct |
79 |
Correct |
151 ms |
501332 KB |
Output is correct |
80 |
Correct |
148 ms |
501548 KB |
Output is correct |
81 |
Correct |
136 ms |
496752 KB |
Output is correct |
82 |
Correct |
161 ms |
504656 KB |
Output is correct |
83 |
Correct |
137 ms |
496032 KB |
Output is correct |
84 |
Correct |
170 ms |
506704 KB |
Output is correct |
85 |
Correct |
155 ms |
502100 KB |
Output is correct |
86 |
Correct |
187 ms |
510800 KB |
Output is correct |
87 |
Correct |
180 ms |
509372 KB |
Output is correct |
88 |
Correct |
185 ms |
510036 KB |
Output is correct |
89 |
Correct |
196 ms |
511928 KB |
Output is correct |
90 |
Correct |
178 ms |
509008 KB |
Output is correct |
91 |
Correct |
181 ms |
509212 KB |
Output is correct |
92 |
Correct |
200 ms |
512392 KB |
Output is correct |
93 |
Correct |
201 ms |
517056 KB |
Output is correct |
94 |
Correct |
175 ms |
507800 KB |
Output is correct |
95 |
Correct |
175 ms |
507984 KB |
Output is correct |
96 |
Correct |
155 ms |
502608 KB |
Output is correct |
97 |
Correct |
154 ms |
502876 KB |
Output is correct |
98 |
Correct |
138 ms |
496980 KB |
Output is correct |
99 |
Correct |
136 ms |
495916 KB |
Output is correct |
100 |
Execution timed out |
1093 ms |
697172 KB |
Time limit exceeded |
101 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
495696 KB |
Output is correct |
2 |
Correct |
140 ms |
495696 KB |
Output is correct |
3 |
Correct |
150 ms |
496320 KB |
Output is correct |
4 |
Correct |
135 ms |
495700 KB |
Output is correct |
5 |
Correct |
137 ms |
495960 KB |
Output is correct |
6 |
Correct |
134 ms |
495676 KB |
Output is correct |
7 |
Correct |
143 ms |
495740 KB |
Output is correct |
8 |
Correct |
137 ms |
495824 KB |
Output is correct |
9 |
Correct |
148 ms |
495712 KB |
Output is correct |
10 |
Correct |
286 ms |
537156 KB |
Output is correct |
11 |
Correct |
143 ms |
500308 KB |
Output is correct |
12 |
Correct |
185 ms |
509780 KB |
Output is correct |
13 |
Correct |
138 ms |
497236 KB |
Output is correct |
14 |
Correct |
144 ms |
500048 KB |
Output is correct |
15 |
Correct |
142 ms |
499540 KB |
Output is correct |
16 |
Correct |
145 ms |
500404 KB |
Output is correct |
17 |
Correct |
136 ms |
495964 KB |
Output is correct |
18 |
Correct |
142 ms |
499016 KB |
Output is correct |
19 |
Correct |
133 ms |
496236 KB |
Output is correct |
20 |
Correct |
131 ms |
495708 KB |
Output is correct |
21 |
Correct |
152 ms |
499792 KB |
Output is correct |
22 |
Correct |
160 ms |
505168 KB |
Output is correct |
23 |
Correct |
157 ms |
503892 KB |
Output is correct |
24 |
Correct |
138 ms |
497748 KB |
Output is correct |
25 |
Correct |
136 ms |
497656 KB |
Output is correct |
26 |
Correct |
132 ms |
496224 KB |
Output is correct |
27 |
Correct |
131 ms |
495960 KB |
Output is correct |
28 |
Correct |
141 ms |
497768 KB |
Output is correct |
29 |
Correct |
130 ms |
495916 KB |
Output is correct |
30 |
Correct |
130 ms |
495788 KB |
Output is correct |
31 |
Correct |
130 ms |
495888 KB |
Output is correct |
32 |
Correct |
132 ms |
495888 KB |
Output is correct |
33 |
Correct |
136 ms |
495952 KB |
Output is correct |
34 |
Correct |
130 ms |
495696 KB |
Output is correct |
35 |
Correct |
134 ms |
495844 KB |
Output is correct |
36 |
Correct |
132 ms |
495956 KB |
Output is correct |
37 |
Correct |
136 ms |
496556 KB |
Output is correct |
38 |
Runtime error |
538 ms |
1005380 KB |
Execution killed with signal 11 |
39 |
Halted |
0 ms |
0 KB |
- |