結果

問題 No.2922 Rose Garden
ユーザー Tasneem Ahmed
提出日時 2024-10-12 16:56:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,394 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 67,584 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 16:56:41
合計ジャッジ時間 4,556 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>  // For abs()
using namespace std;

int main() {
    int n, s, b;
    cin >> n >> s >> b;
    int H[n];

    for (int i = 0; i < n; i++) {
        cin >> H[i];
    }

    // Initialize the first height difference for comparison
    int prev_hd = abs(H[1] - H[0]);

    for (int i = 1; i < n; i++) {
        int hd = H[i] - H[i-1];  // Current height difference (can be negative)

        // If current and previous height differences are the same, no stamina is consumed
        if (abs(hd) == prev_hd) {
            continue;
        }

        if (hd > 0) {
            // If height difference is positive (jumping upward)
            if (hd > b) {
                // Calculate how many stamina points are needed to cover the jump
                int jumps = (hd + b - 1) / b;  // Equivalent to ceil(hd / b)
                s -= jumps;  // Deduct stamina for the required jumps
            } else {
                // Single jump if hd <= b
                s--;  // One stamina consumed
            }
        }

        // If stamina becomes insufficient, print No and exit
        if (s < 0) {
            cout << "No";
            return 0;
        }

        // Update the previous height difference for the next iteration
        prev_hd = abs(hd);
    }

    // If all scaffolds are traversed successfully, print Yes
    cout << "Yes";
    return 0;
}
0