結果
問題 |
No.595 登山
|
ユーザー |
|
提出日時 | 2017-11-10 23:32:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,376 bytes |
コンパイル時間 | 1,557 ms |
コンパイル使用メモリ | 172,132 KB |
実行使用メモリ | 7,164 KB |
最終ジャッジ日時 | 2024-11-24 15:38:39 |
合計ジャッジ時間 | 3,090 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 WA * 20 |
ソースコード
#include <bits/stdc++.h> #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template <typename T> constexpr T INF = numeric_limits<T>::max() / 64; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; ll P; cin >> N >> P; vector<ll> H(N); for (int i = 0; i < N; i++) { cin >> H[i]; } vector<ll> point; bool falling = true; for (int i = 0; i < N - 1; i++) { if (falling and H[i + 1] > H[i]) { point.push_back(H[i]); falling = false; } else if ((not falling) and H[i + 1] < H[i]) { point.push_back(H[i]); falling = true; } } point.push_back(H[N - 1]); const int size = point.size(); ll sum = 0; for (int i = 0; i < size - 1; i++) { if (i % 2 == 0) { sum += min(P, point[i + 1] - point[i]); } } cout << sum << endl; return 0; }