結果

問題 No.595 登山
ユーザー NekosyndromeNekosyndrome
提出日時 2017-11-10 23:18:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 1,500 ms
コード長 976 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 143,820 KB
実行使用メモリ 8,240 KB
最終ジャッジ日時 2023-08-16 05:16:14
合計ジャッジ時間 4,483 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,496 KB
testcase_01 AC 2 ms
5,640 KB
testcase_02 AC 2 ms
5,576 KB
testcase_03 AC 2 ms
5,488 KB
testcase_04 AC 25 ms
8,064 KB
testcase_05 AC 9 ms
6,464 KB
testcase_06 AC 22 ms
7,908 KB
testcase_07 AC 4 ms
5,836 KB
testcase_08 AC 5 ms
5,996 KB
testcase_09 AC 22 ms
7,852 KB
testcase_10 AC 16 ms
7,288 KB
testcase_11 AC 15 ms
7,116 KB
testcase_12 AC 4 ms
5,788 KB
testcase_13 AC 9 ms
6,316 KB
testcase_14 AC 20 ms
8,116 KB
testcase_15 AC 20 ms
8,240 KB
testcase_16 AC 20 ms
8,140 KB
testcase_17 AC 20 ms
8,124 KB
testcase_18 AC 20 ms
8,140 KB
testcase_19 AC 29 ms
8,128 KB
testcase_20 AC 29 ms
8,156 KB
testcase_21 AC 30 ms
8,184 KB
testcase_22 AC 29 ms
8,236 KB
testcase_23 AC 29 ms
8,140 KB
testcase_24 AC 2 ms
5,496 KB
testcase_25 AC 2 ms
5,528 KB
testcase_26 AC 31 ms
8,220 KB
testcase_27 AC 24 ms
8,176 KB
testcase_28 AC 24 ms
8,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 200005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n;
long long in[M],p;
long long dp[M][2];//fr,bk

LL calc()
{
	dp[1][0] = 0;
	dp[1][1] = (1LL)<<60;
	REP(i,2,n)
	{
		dp[i][0] = dp[i-1][0] + min(max(in[i]-in[i-1],0LL), p);
		dp[i][1] = dp[i-1][1] + min(max(in[i-1]-in[i], 0LL), p);

		dp[i][1] = min(dp[i][1], dp[i-1][0] + p);
		dp[i][0] = min(dp[i][0], dp[i-1][1] + p);
	}

	return min(dp[n][0], dp[n][1]);
}
int main()
{
	while(~scanf("%d %lld",&n,&p))
	{
		REP(i,1,n) scanf("%lld",&in[i]);
		printf("%lld\n", calc());


	}
	return 0;
}

0