Official
A - 倉庫の出荷管理 / Warehouse Shipment Management Editorial
by
A - 倉庫の出荷管理 / Warehouse Shipment Management Editorial
by
MtSaka
初心者の方へ
- 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 入門用コンテンツです。
問題文の指示通りに各商品の在庫数を配列として管理し、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:
