結果

問題 No.595 登山
ユーザー kotamanegi
提出日時 2017-11-10 22:52:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,398 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 104,584 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-24 13:07:43
合計ジャッジ時間 3,006 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int main() {
	long long n, k;
	cin >> n >> k;
	long long ans[2] = { 0,LONG_INF };
	vector<long long> wow;
	REP(i, n) {
		long long tmp;
		cin >> tmp;
		wow.push_back(tmp);
	}
	wow.push_back(-1);
	int backing = 0;
	for (int i = 1;i < n+1;++i) {
		if (wow[i - 1] > wow[i]) {
			//backing ~ i-1
			long long a = min(ans[0] + wow[i - 1] - wow[backing], ans[1] + k + wow[i - 1] - wow[backing]);
			long long b = min(ans[0] + k, ans[1] + k);
			backing = i;
			ans[0] = a;
			ans[1] = b;
		}
	}
	cout << min(ans[0], ans[1]) << endl;
	return 0;
}
0