Official
A - バスの出発時刻 / Bus Departure Time Editorial
by
A - バスの出発時刻 / Bus Departure Time Editorial
by
MtSaka
初心者の方へ
- AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
- また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
- Python入門 AtCoder Programming Guide for beginners (APG4bPython) は、競技プログラミングのための Python 入門用コンテンツです。
問題文の通り、答えは \(T_1,T_2,T_3,\ldots,T_N\) の最大値に \(K\) を加えたものです。
\(T\) の最大値の計算は以下のステップを行うことでできます。
暫定の最大値 \(M\) を持ち、\(M=T_1\) と初期化します。\(i=2,3,\ldots,N\) について \(M \leftarrow \max(M,T_i)\) と更新します。
これらの操作の後 \(M\) は \(T\) の最大値となっています。
また、各種言語の標準機能には配列の最大値を求める機能があることがあります。例えば、a の最大値は C++ では *std::max_element(a.begin(),a.end()) 、Pythonでは max(a) などで取得できます。
実装例(C++)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> t(n);
for (auto& e : t) cin >> e;
cout << *max_element(t.begin(), t.end()) + k << endl;
}
posted:
last update:
