結果

問題 No.595 登山
ユーザー vjudge1
提出日時 2025-08-23 12:26:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 536 bytes
コンパイル時間 3,027 ms
コンパイル使用メモリ 275,660 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2025-08-23 12:26:32
合計ジャッジ時間 6,520 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std; 
const int MAXN=200010;
long long h[MAXN];
long long r[MAXN];
long long l[MAXN]; 
long long n;
long long p;
int main(){
	cin>>n>>p; 
	for(int i=0;i<n;++i)cin>>h[i]; 
	for(int i=1;i<n;++i)r[i]=r[i-1]+max(0LL,h[i]-h[i-1]); 
	for(int i=n-2;i>=0;--i)l[i]=l[i+1]+max(0LL,h[i]-h[i+1]); 
	long long c1=r[n-1];
	long long c2=(n-1)*p;
	long long move=LLONG_MAX;
	for(int x=0;x<n-1;++x)move=min(move,r[x]+l[x+1]);
	long long c3=move+p; 
	long long ans=min({c1,c2,c3});
	cout<<ans<<endl;
	return 0;
}
0