結果

問題 No.595 登山
ユーザー vjudge1
提出日時 2025-08-23 18:53:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 1,500 ms
コード長 715 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 162,188 KB
実行使用メモリ 12,284 KB
最終ジャッジ日時 2025-08-23 18:53:44
合計ジャッジ時間 3,028 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000010;
const int mod=998244353;
typedef long long ll;
int n,p;
int a[N];
int dp[N][2];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("graph.in","r",stdin);
	// freopen("graph.out","w",stdout);
	cin>>n>>p;
	for(int i=1;i<=n;i++)cin>>a[i];
	dp[1][0]=0;
	dp[1][1]=p;
	for(int i=2;i<=n;i++){
		for(int j=0;j<2;j++){
			int val=a[i]-a[i-1];
			if(j)val=-val;
			val=max(val,0ll);
			dp[i][j]=dp[i-1][j]+val;
		}
		dp[i][0]=min({dp[i][0],dp[i-1][0]+p,dp[i-1][1]+p});
		dp[i][1]=min({dp[i][1],dp[i-1][0]+p,dp[i-1][1]+p});
	}
	// cerr<<dp[4][1]<<"\n";
	cout<<min(dp[n][0],dp[n][1])<<"\n";
	return 0;
}
/*

*/
0