結果

問題 No.2015 Stair Counter
ユーザー startcppstartcpp
提出日時 2022-07-28 01:00:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 64,936 KB
実行使用メモリ 6,688 KB
最終ジャッジ日時 2023-09-24 14:00:17
合計ジャッジ時間 4,570 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 37 ms
4,384 KB
testcase_02 AC 41 ms
4,376 KB
testcase_03 AC 42 ms
4,380 KB
testcase_04 AC 34 ms
4,380 KB
testcase_05 AC 31 ms
4,380 KB
testcase_06 AC 46 ms
4,500 KB
testcase_07 AC 46 ms
4,380 KB
testcase_08 AC 46 ms
4,376 KB
testcase_09 AC 25 ms
4,380 KB
testcase_10 AC 26 ms
4,376 KB
testcase_11 AC 29 ms
4,380 KB
testcase_12 AC 24 ms
4,380 KB
testcase_13 AC 26 ms
4,376 KB
testcase_14 AC 30 ms
4,380 KB
testcase_15 AC 36 ms
5,312 KB
testcase_16 AC 58 ms
6,120 KB
testcase_17 AC 25 ms
5,884 KB
testcase_18 AC 50 ms
5,732 KB
testcase_19 AC 61 ms
6,408 KB
testcase_20 AC 31 ms
6,688 KB
testcase_21 AC 35 ms
4,376 KB
testcase_22 AC 40 ms
4,376 KB
testcase_23 AC 44 ms
4,376 KB
testcase_24 AC 35 ms
4,380 KB
testcase_25 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int a[200001];
int b[200002];

bool solve() {
	int i;
	rep(i, n + 1) b[i] = 0;
	
	b[0] = m;
	rep(i, n) {
		int x = a[i + 1] - b[i + 1];
		if (x < 0 || x > b[i]) { return false; }
		b[i + 1] += x;
		b[i + 2] += b[i] - x;
	}
	
	for (i = 1; i <= n; i++) if (b[i] != a[i]) { return false; }
	return true;
}

signed main() {
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		for (int i = 0; i < n; i++) cin >> a[i + 1];
		bool res = solve();
		if (res) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}
0