Official
A - 合格者への拍手 / Applause for the Successful Candidates Editorial
by
A - 合格者への拍手 / Applause for the Successful Candidates Editorial
by
kyopro_friends
初心者の方へ
- 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 入門用コンテンツです。
問題文の指示通り、 \(P_1,\ldots,P_N\) のうち \(K\) 以上のものの合計を求めればよいです。
実装例 (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int>a(n);
for(int i=0; i<n; i++) cin >> a[i];
int ans = 0;
for(int i=0; i<n; i++){
if(a[i] >= k){
ans += a[i];
}
}
cout << ans << endl;
}
実装例 (Python)
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for a in A:
if a >= K:
ans += a
print(ans)
posted:
last update:
