Official
A - Second Half Sum Editorial
by
A - Second Half Sum Editorial
by
physics0523
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは 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 入門用コンテンツです。
原案: admin
以下の \(2\) 点を組み合わせるとこの問題に正解できます。
- 配列 \(A\) を標準入力から受け取る
- 配列 \(A\) の後半部分の総和を取り、出力する
例えば、これらの双方に for ループを活用することができます。
実装例 (C++):
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,s=0;
cin >> n;
vector<int> a(n);
for(auto &nx : a){cin >> nx;}
for(int i=(n/2);i<n;i++){
s+=a[i];
}
cout << s << "\n";
return 0;
}
