# Untitled

unknown
plain_text
3 years ago
1.6 kB
4
Indexable
Never
```#include <stdio.h>
int H[20];
int even[20];
int C[20];
int N,S,T;
int max_energy,max_step;
int step[20];
void let(int s,int t,int st);
void end(int st);
int main(void){
int st;
max_energy=0;
max_step=0;
scanf("%d %d %d",&N,&S,&T);
for(int i=1;i<=N;i++){
scanf("%d",&H[i]);
}
for(int i=1;i<=N;i++){
scanf("%d",&C[i]);
}
for(int i=1;i<=N;i++){
even[i]=0;
}
step[0]=S;
even[S]=1;
let(S,T,1);
printf("%d %d\n",max_energy,max_step);
return 0;
}
void let(int s,int t,int st){
//printf("A");
int g=0;
for(int i=1;i<=N;i++){
g=g+even[i];
if(g==N){
end(st);
return;
}
}
if(even[s-1]==0){
step[st]=s-1;
even[s-1]=1;
let(s-1,t,st+1);
}
if(even[s+1]==0){
step[st]=s+1;
even[s+1]=1;
let(s+1,t,st+1);
}
for(int i=1;i<=N;i++){
if(even[i]==0 && C[i]==C[s]){
step[st]=i;
even[i]=1;
let(i,t,st+1);
}
}

}
void end(int st){
//printf("B");
int energy=0,a=0;
for(int i=st-1;i>0;i--){
a=(H[step[st]]-H[step[st-1]]);
if(a>=0){
energy=energy+a;
}
else{
energy=energy-a;
}

}
if(energy>max_energy){
max_energy=energy;
max_step=st;
}
else if(energy==max_energy && st>max_step){
max_step=st;
}
}```