#include <bits/stdc++.h>
using namespace std;
#define ll long long
int check(vector<string> action,vector<int> exp, vector<int> levels){
int ans =0, ce= 0;
for (int i=0;i<action.size();i++){
int n = stoi(action[i]+ string());
if (ce<=levels[n]) {ans += 1; ce += exp[n];}
else break;
}
return ans;
}
int gen(string s,vector<int> exp, vector<int> levels){
int ans =0;
string a,b,c,d,e,f,g,h,z;
if (s.size()==1){
vector<vector<string>> y= {{"0"}};
for (int i =0;i<y.size();i++){
ans = max(ans,check(y[i],exp,levels));
}
}
else if (s.size() ==2){
vector<vector<string>> y= {{"0","1"},{"1","0"}};
for (int i =0;i<y.size();i++){
ans = max(ans,check(y[i],exp,levels));}
}
else if (s.size() ==3){
vector<vector<string>> y={{"0","1","2"},{"0","2","1"},{"1","2","0"},{"1","0","2"},{"2","0","1"},{"2","1","0"}};
for (int i =0;i<y.size();i++){
ans = max(ans,check(y[i],exp,levels));}
}
else if (s.size() ==4){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++){
vector<string> t = {"0","1","2","3"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
ans = max(ans,check(t,exp,levels));
}
}
else if (s.size() ==5){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++){
vector<string> t = {"0","1","2","3","4"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
d= t[l];
t[l]= t[3]; t[3] = d;
ans = max(ans,check(t,exp,levels));
}
}
else if (s.size() ==6){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++){
vector<string> t = {"0","1","2","3","4","5"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
d= t[l];
t[l]= t[3]; t[3] = d;
e = t[m];
t[m] = t[4]; t[4] = e;
ans = max(ans,check(t,exp,levels));
}
}
else if (s.size() ==7){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++){
vector<string> t = {"0","1","2","3","4","5","6"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
d= t[l];
t[l]= t[3]; t[3] = d;
e = t[m];
t[m] = t[4]; t[4] = e;
f = t[n];
t[n] = t[5]; t[5] = f;
ans = max(ans,check(t,exp,levels));
}
}
else if (s.size() ==8){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++)
for (int o =6;o<s.size(); o++){
vector<string> t = {"0","1","2","3","4","5","6","7"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
d= t[l];
t[l]= t[3]; t[3] = d;
e = t[m];
t[m] = t[4]; t[4] = e;
f = t[n];
t[n] = t[5]; t[5] = f;
g = t[o];
t[o] = t[6]; t[6] = g;
ans = max(ans,check(t,exp,levels));
}
}
else if (s.size() ==9){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++)
for (int o =6;o<s.size(); o++)
for (int p =7;p<s.size(); p++){
vector<string> t = {"0","1","2","3","4","5","6","7","8"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
d= t[l];
t[l]= t[3]; t[3] = d;
e = t[m];
t[m] = t[4]; t[4] = e;
f = t[n];
t[n] = t[5]; t[5] = f;
g = t[o];
t[o] = t[6]; t[6] = g;
h = t[p];
t[p] = t[7]; t[7] = h;
ans = max(ans,check(t,exp,levels));
}
}
else if (s.size() ==10){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++)
for (int o =6;o<s.size(); o++)
for (int p =7;p<s.size(); p++)
for (int q =8;q<s.size(); q++){
vector<string> t = {"0","1","2","3","4","5","6","7","8","9"};
a= t[i];
t[i] = t[0]; t[0] = a;
b= t[j];
t[j] = t[1]; t[1] = b;
c= t[k];
t[k] = t[2]; t[2] = c;
d= t[l];
t[l]= t[3]; t[3] = d;
e = t[m];
t[m] = t[4]; t[4] = e;
f = t[n];
t[n] = t[5]; t[5] = f;
g = t[o];
t[o] = t[6]; t[6] = g;
h = t[p];
t[p] = t[7]; t[7] = h;
z= t[q];
t[q] = t[8]; t[8] = q;
ans = max(ans,check(t,exp,levels));
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
int n,x,ce=0,c=0; cin>>n;
vector<int> exp, levels;
for (int i =0; i<n; i++){
cin>>x;
exp.push_back(x);}
for (int i =0; i<n; i++){
cin>>x;
levels.push_back(x);
}
if (n<=10){
string z="";
int m =0;
for (int i=0; i<n;i++){z+="1";}
cout<<gen(z,exp,levels);}
else{
sort(exp.begin(),exp.end());
while (ce<=levels[0]){
if (c==n){break;}
ce += exp[c];
c+=1;
}
cout<<c;}
}
Compilation message
Main.cpp: In function 'int check(std::vector<std::__cxx11::basic_string<char> >, std::vector<int>, std::vector<int>)':
Main.cpp:6:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | for (int i=0;i<action.size();i++){
| ~^~~~~~~~~~~~~~
Main.cpp: In function 'int gen(std::string, std::vector<int>, std::vector<int>)':
Main.cpp:18:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i =0;i<y.size();i++){
| ~^~~~~~~~~
Main.cpp:24:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i =0;i<y.size();i++){
| ~^~~~~~~~~
Main.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i =0;i<y.size();i++){
| ~^~~~~~~~~
Main.cpp:33:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:34:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:35:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int k =2;k<s.size(); k++){
| ~^~~~~~~~~
Main.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int l =3;l<s.size(); l++){
| ~^~~~~~~~~
Main.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:66:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:67:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:68:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int m =4;m<s.size(); m++){
| ~^~~~~~~~~
Main.cpp:84:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:85:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:87:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:88:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:89:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int n =5;n<s.size(); n++){
| ~^~~~~~~~~
Main.cpp:107:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:108:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:109:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:110:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:111:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:112:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:113:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int o =6;o<s.size(); o++){
| ~^~~~~~~~~
Main.cpp:133:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
133 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:134:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
134 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:135:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:136:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:137:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:138:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
138 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:139:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for (int o =6;o<s.size(); o++)
| ~^~~~~~~~~
Main.cpp:140:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for (int p =7;p<s.size(); p++){
| ~^~~~~~~~~
Main.cpp:162:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
162 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:163:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
163 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:164:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
164 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:165:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
165 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:166:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
166 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:167:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
167 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:168:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
168 | for (int o =6;o<s.size(); o++)
| ~^~~~~~~~~
Main.cpp:169:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
169 | for (int p =7;p<s.size(); p++)
| ~^~~~~~~~~
Main.cpp:170:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
170 | for (int q =8;q<s.size(); q++){
| ~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:208:13: warning: unused variable 'm' [-Wunused-variable]
208 | int m =0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
212 KB |
Output is correct |
2 |
Correct |
19 ms |
320 KB |
Output is correct |
3 |
Execution timed out |
2089 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
6052 KB |
Output is correct |
2 |
Correct |
168 ms |
6208 KB |
Output is correct |
3 |
Correct |
139 ms |
6384 KB |
Output is correct |
4 |
Correct |
136 ms |
6260 KB |
Output is correct |
5 |
Correct |
140 ms |
5868 KB |
Output is correct |
6 |
Correct |
129 ms |
5732 KB |
Output is correct |
7 |
Correct |
139 ms |
6512 KB |
Output is correct |
8 |
Correct |
139 ms |
6024 KB |
Output is correct |
9 |
Correct |
144 ms |
5884 KB |
Output is correct |
10 |
Correct |
137 ms |
5860 KB |
Output is correct |
11 |
Correct |
123 ms |
5620 KB |
Output is correct |
12 |
Correct |
124 ms |
6244 KB |
Output is correct |
13 |
Correct |
135 ms |
5676 KB |
Output is correct |
14 |
Correct |
130 ms |
6040 KB |
Output is correct |
15 |
Correct |
121 ms |
6240 KB |
Output is correct |
16 |
Correct |
129 ms |
6172 KB |
Output is correct |
17 |
Correct |
132 ms |
5924 KB |
Output is correct |
18 |
Correct |
146 ms |
5864 KB |
Output is correct |
19 |
Correct |
151 ms |
6204 KB |
Output is correct |
20 |
Correct |
133 ms |
6208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
212 KB |
Output is correct |
2 |
Correct |
19 ms |
320 KB |
Output is correct |
3 |
Execution timed out |
2089 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
212 KB |
Output is correct |
2 |
Correct |
19 ms |
320 KB |
Output is correct |
3 |
Execution timed out |
2089 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |