公式

B - テストの目標点 / Target Score for the Test 解説 by kyopro_friends


各科目について、 \(T\) 点以上を達成するために必要な追加課題の回数を求め、その合計が \(M\) 以下であるかどうかを確かめればよいです。

実装例 (C++)

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

int main(){
  int n, m, t;
  cin >> n >> m >> t;
  vector<int>a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  int count = 0;
  for(int i=0; i<n; i++){
    if(a[i] < t){
      count += t - a[i];
    }
  }

  if(count <= m){
    cout << count << endl;
  }else{
    cout << -1 << endl;
  }
}

実装例 (Python)

N, M, T = map(int, input().split())
A = list(map(int, input().split()))

count = 0
for a in A:
  if a < T:
    count += T - a

if count <= M:
  print(count)
else:
  print(-1)

投稿日時:
最終更新: