#include "jelly.h"
#include <cstdio>
#include <cassert>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int find_maximum_unique(int x, int y, std::vector<int> arr, std::vector<int> brr) {
int n = arr.size();
bool ok=true;
bool okay=true;
int sum1=0;
for (int i =0;i<n;++i){
if (arr[i]!=brr[i]){
ok=false;
}
if (i>0){
if (brr[i]!=brr[i-1])okay=false;
}
sum1+=arr[i];
}
if (okay){
vector<pair<int,int>>crr(n);
for (int i=0;i<n;++i){
crr[i]={arr[i],brr[i]};
}
sort(crr.begin(),crr.end());
int ans=0;
n--;
while(n>=0){
if (y-crr[n].second>=0){
y-=crr[n].second;
--n;
ans++;
}
else break;
}
for (int i =0;i<=n;++i){
if (x-crr[i].first<0)break;
x-=crr[i].first;
ans++;
}
return ans;
}
if (!ok){
int dp2[n][sum1+1];
memset(dp2,0,sizeof dp2);
for (int i =0;i<n;++i){
dp2[i][0]=1;
for (int j =0;j<=sum1;++j){
if (dp2[i][j]==1){
dp2[i+1][j+arr[i]]=1;
}
dp2[i+1][j]=max(dp2[i][j],dp2[i+1][j]);
}
}
vector<int>ans;
ans.push_back(0);
for (int i = 1;i<x;++i){
if (dp2[n][i]==1)ans.push_back(i);
}
ans.push_back(x);
int dp [n+1][ans.size()][y+1];
memset(dp,0,sizeof dp);
for (int i =1;i<=n;++i){
for (int j =0;j<ans.size();++j){
for (int k =0;k<=y;++k){
dp[i][j][k] = max({(ans[j]-arr[i-1]>=0)?dp[i-1][find(ans.begin(),ans.end(),ans[j]-arr[i-1])-ans.begin()][k]+1:0,(k-brr[i-1]>=0)?dp[i-1][j][k-brr[i-1]]+1:0,dp[i-1][j][k],dp[i][j][k]});
}
}
}
return dp[n][ans.size()-1][y];}
else {
int dp1[n+1][x+y+1];
memset(dp1,0,sizeof dp1);
for (int i =1;i<=n;++i){
for (int j =0;j<=x+y;++j){
dp1[i][j] = max({(j-arr[i-1]>=0)?dp1[i-1][j-arr[i-1]]+1:0,dp1[i][j],dp1[i-1][j]});
}
}
return dp1[n][x+y];
}
}
Compilation message
jelly.cpp: In function 'int find_maximum_unique(int, int, std::vector<int>, std::vector<int>)':
jelly.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int j =0;j<ans.size();++j){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1020 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
300 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
2 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
324 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
2 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
300 KB |
Output is correct |
56 |
Correct |
1 ms |
332 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
304 KB |
Output is correct |
59 |
Correct |
2 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
1 ms |
304 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
304 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
1 ms |
332 KB |
Output is correct |
67 |
Correct |
1 ms |
332 KB |
Output is correct |
68 |
Correct |
1 ms |
332 KB |
Output is correct |
69 |
Correct |
1 ms |
332 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
1 ms |
332 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
1 ms |
332 KB |
Output is correct |
76 |
Correct |
2 ms |
332 KB |
Output is correct |
77 |
Correct |
1 ms |
332 KB |
Output is correct |
78 |
Correct |
2 ms |
304 KB |
Output is correct |
79 |
Correct |
1 ms |
332 KB |
Output is correct |
80 |
Correct |
1 ms |
300 KB |
Output is correct |
81 |
Correct |
1 ms |
332 KB |
Output is correct |
82 |
Correct |
2 ms |
332 KB |
Output is correct |
83 |
Correct |
2 ms |
304 KB |
Output is correct |
84 |
Correct |
1 ms |
296 KB |
Output is correct |
85 |
Correct |
1 ms |
332 KB |
Output is correct |
86 |
Correct |
1 ms |
332 KB |
Output is correct |
87 |
Correct |
1 ms |
308 KB |
Output is correct |
88 |
Correct |
2 ms |
332 KB |
Output is correct |
89 |
Correct |
1 ms |
332 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
1 ms |
332 KB |
Output is correct |
92 |
Correct |
1 ms |
332 KB |
Output is correct |
93 |
Correct |
1 ms |
332 KB |
Output is correct |
94 |
Correct |
1 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
300 KB |
Output is correct |
96 |
Correct |
1 ms |
332 KB |
Output is correct |
97 |
Correct |
1 ms |
332 KB |
Output is correct |
98 |
Correct |
1 ms |
332 KB |
Output is correct |
99 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
79352 KB |
Output is correct |
2 |
Correct |
148 ms |
141300 KB |
Output is correct |
3 |
Correct |
160 ms |
140484 KB |
Output is correct |
4 |
Correct |
153 ms |
147748 KB |
Output is correct |
5 |
Correct |
153 ms |
143684 KB |
Output is correct |
6 |
Correct |
155 ms |
145548 KB |
Output is correct |
7 |
Correct |
155 ms |
147140 KB |
Output is correct |
8 |
Correct |
148 ms |
143456 KB |
Output is correct |
9 |
Correct |
181 ms |
142240 KB |
Output is correct |
10 |
Correct |
169 ms |
152176 KB |
Output is correct |
11 |
Correct |
82 ms |
74300 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
95 ms |
87876 KB |
Output is correct |
14 |
Correct |
85 ms |
78020 KB |
Output is correct |
15 |
Correct |
91 ms |
84548 KB |
Output is correct |
16 |
Correct |
94 ms |
78092 KB |
Output is correct |
17 |
Correct |
91 ms |
85584 KB |
Output is correct |
18 |
Correct |
88 ms |
85168 KB |
Output is correct |
19 |
Correct |
94 ms |
76100 KB |
Output is correct |
20 |
Correct |
79 ms |
77168 KB |
Output is correct |
21 |
Correct |
86 ms |
79404 KB |
Output is correct |
22 |
Correct |
143 ms |
141388 KB |
Output is correct |
23 |
Correct |
144 ms |
140356 KB |
Output is correct |
24 |
Correct |
151 ms |
147812 KB |
Output is correct |
25 |
Correct |
156 ms |
143684 KB |
Output is correct |
26 |
Correct |
156 ms |
145508 KB |
Output is correct |
27 |
Correct |
162 ms |
146940 KB |
Output is correct |
28 |
Correct |
143 ms |
143456 KB |
Output is correct |
29 |
Correct |
163 ms |
142148 KB |
Output is correct |
30 |
Correct |
156 ms |
152116 KB |
Output is correct |
31 |
Correct |
81 ms |
74328 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
94 ms |
87908 KB |
Output is correct |
34 |
Correct |
84 ms |
78188 KB |
Output is correct |
35 |
Correct |
93 ms |
84464 KB |
Output is correct |
36 |
Correct |
93 ms |
78020 KB |
Output is correct |
37 |
Correct |
88 ms |
85564 KB |
Output is correct |
38 |
Correct |
88 ms |
85172 KB |
Output is correct |
39 |
Correct |
86 ms |
76200 KB |
Output is correct |
40 |
Correct |
86 ms |
77092 KB |
Output is correct |
41 |
Correct |
88 ms |
79352 KB |
Output is correct |
42 |
Correct |
151 ms |
141252 KB |
Output is correct |
43 |
Correct |
144 ms |
140356 KB |
Output is correct |
44 |
Correct |
149 ms |
147864 KB |
Output is correct |
45 |
Correct |
153 ms |
143768 KB |
Output is correct |
46 |
Correct |
152 ms |
145540 KB |
Output is correct |
47 |
Correct |
184 ms |
146932 KB |
Output is correct |
48 |
Correct |
171 ms |
143420 KB |
Output is correct |
49 |
Correct |
159 ms |
142236 KB |
Output is correct |
50 |
Correct |
170 ms |
152080 KB |
Output is correct |
51 |
Correct |
81 ms |
74308 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
95 ms |
87880 KB |
Output is correct |
54 |
Correct |
85 ms |
78104 KB |
Output is correct |
55 |
Correct |
88 ms |
84556 KB |
Output is correct |
56 |
Correct |
81 ms |
78096 KB |
Output is correct |
57 |
Correct |
90 ms |
85572 KB |
Output is correct |
58 |
Correct |
92 ms |
85060 KB |
Output is correct |
59 |
Correct |
83 ms |
76116 KB |
Output is correct |
60 |
Correct |
80 ms |
77172 KB |
Output is correct |
61 |
Correct |
87 ms |
79340 KB |
Output is correct |
62 |
Correct |
178 ms |
141260 KB |
Output is correct |
63 |
Correct |
146 ms |
140364 KB |
Output is correct |
64 |
Correct |
155 ms |
147780 KB |
Output is correct |
65 |
Correct |
157 ms |
143756 KB |
Output is correct |
66 |
Correct |
155 ms |
145620 KB |
Output is correct |
67 |
Correct |
163 ms |
146912 KB |
Output is correct |
68 |
Correct |
180 ms |
143396 KB |
Output is correct |
69 |
Correct |
153 ms |
142268 KB |
Output is correct |
70 |
Correct |
157 ms |
152128 KB |
Output is correct |
71 |
Correct |
89 ms |
74308 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
96 ms |
87996 KB |
Output is correct |
74 |
Correct |
87 ms |
78052 KB |
Output is correct |
75 |
Correct |
96 ms |
84604 KB |
Output is correct |
76 |
Correct |
89 ms |
78024 KB |
Output is correct |
77 |
Correct |
99 ms |
85480 KB |
Output is correct |
78 |
Correct |
91 ms |
85156 KB |
Output is correct |
79 |
Correct |
92 ms |
76228 KB |
Output is correct |
80 |
Correct |
89 ms |
77176 KB |
Output is correct |
81 |
Correct |
86 ms |
79240 KB |
Output is correct |
82 |
Correct |
148 ms |
141232 KB |
Output is correct |
83 |
Correct |
155 ms |
140364 KB |
Output is correct |
84 |
Correct |
160 ms |
147780 KB |
Output is correct |
85 |
Correct |
154 ms |
143684 KB |
Output is correct |
86 |
Correct |
147 ms |
145604 KB |
Output is correct |
87 |
Correct |
154 ms |
146864 KB |
Output is correct |
88 |
Correct |
157 ms |
143556 KB |
Output is correct |
89 |
Correct |
152 ms |
142192 KB |
Output is correct |
90 |
Correct |
175 ms |
152120 KB |
Output is correct |
91 |
Correct |
79 ms |
74332 KB |
Output is correct |
92 |
Correct |
1 ms |
332 KB |
Output is correct |
93 |
Correct |
93 ms |
87880 KB |
Output is correct |
94 |
Correct |
84 ms |
78004 KB |
Output is correct |
95 |
Correct |
92 ms |
84560 KB |
Output is correct |
96 |
Correct |
86 ms |
78148 KB |
Output is correct |
97 |
Correct |
101 ms |
85676 KB |
Output is correct |
98 |
Correct |
100 ms |
85172 KB |
Output is correct |
99 |
Correct |
81 ms |
76116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |