Official

A - レシピのアレンジ料理 / Arranged Dish from a Recipe Editorial by kyopro_friends


初心者の方へ


問題文の指示通り、 \(A_{B_j}+S_j\) の合計を求めればよいです。

多くのプログラミング言語では、配列・リストの添字は \(0\) から始まることに注意してください。

また、一部の言語ではオーバーフローに注意してください。

実装例 (C++)

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

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

  long long ans = 0;
  for(int i=0; i<m; i++){
    int b, x;
    cin >> b >> x;
    ans += a[b-1] + x;
  }
  cout << ans << endl;
}

実装例 (Python)

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

ans = 0
for _ in range(M):
  b, s = map(int, input().split())
  ans += A[b-1] + s

print(ans)

posted:
last update: