Official

B - Climbing Takahashi Editorial by kyopro_friends


この問題のように「~である限り~する」という処理を行うには、while 文が便利です。実装によっては高橋君が右端の台まで到達するケースに注意してください。

実装例(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]);
}

実装例(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: