Official

A - バッテリー残量と充電器の到着 / Battery Level and Charger Arrival Editorial by kyopro_friends


問題文にあるとおり、与えられた \(W_i\) それぞれについて、 \(W_i-D\times K\)\(1\) 以上であるかどうかを調べればよいです。 オーバーフローに注意してください。

実装例 (C++)

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

int main(){
  int n, d, k;
  cin >> n >> d >> k;
  vector<int>w(n);
  for(int i=0; i<n; i++) cin >> w[i];

  int ans=0;
  for(int i=0; i<n; i++){
    if(w[i] - (long long) d * k >= 1){
      ans++;
    }
  }
  cout << ans << endl;
}

実装例 (Python)

N, D, K = map(int, input().split())
W = list(map(int, input().split()))

ans = 0
for w in W:
  if w - D * K >= 1:
    ans += 1

print(ans)

posted:
last update: