Official

B - Climbing Takahashi Editorial by en_translator


The process of “doing something as long as some condition holds” can be typically achieved by a while statement. Be careful of the case when Takahashi reaches the rightmost platform, depending on implementation.

Sample code (C)

#include<stdio.h>

int h[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",h+i);
	
	int pos=0;
	while(pos+1<n&&h[pos]<h[pos+1])pos++;
	printf("%d\n",h[pos]);
}

Sample code (Python)

N=int(input())
H=list(map(int,input().split()))
pos=0
while pos+1<N and H[pos]<H[pos+1]: pos+=1
print(H[pos])

posted:
last update: