# Untitled

unknown
plain_text
2 years ago
1.6 kB
1
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;

let(S,T,0);
printf("%d %d",max_energy,max_step);
return 0;
}
void let(int s,int t,int st){
printf("A");
if(s==t){
end(st);
return;
}
else{
if(even[s-1]==0){
step[st]=s-1;
even[s-1]=1;
let(s-1,t,st+1);
}
if(even[s+1]==0){
st++;
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 && even[i]==even[s]){
st++;
step[st]=s-1;
even[i]=1;
let(i,t,st+1);
}
}
}
}
void end(int st){
printf("B");
int energy=0,a;
for(int i=st;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;
}
}```