結果

問題 No.2648 [Cherry 6th Tune D] 一次元の馬
ユーザー Manuel
提出日時 2024-02-23 22:12:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 193,972 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-20 02:03:42
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void solve() {
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	bool cred = true;
	for (int i = 1; i < n; ++i) {
		if (a[i - 1] >= a[i]) cred = false;
	}
	if (cred) {
		cout << 0 << "\n";
		return;
	}
	long long ans = 0;
	for (int i = 1; i < n; ++i) {
		if (a[i - 1] < a[i]) continue;
		ans = max(a[i - 1] - a[i] + 1, ans);
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int test = 1;
	cin >> test;
	while (test--) {
		solve();
	}
	return 0;
}
0