Official

A - 倉庫の出荷管理 / Warehouse Shipment Management Editorial by MtSaka


初心者の方へ


問題文の指示通りに各商品の在庫数を配列として管理し、for文を用いて依頼を順番に処理していけばよいです。

実装例(C++)

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> r(n);
    for (auto& e : r) cin >> e;
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        int f, s;
        cin >> f >> s;
        f--;
        if (r[f] >= s) {
            r[f] -= s;
            ans++;
        }
    }
    cout << ans << endl;
}

posted:
last update: