Official
A - 倉庫の在庫管理 / Warehouse Inventory Management Editorial
by
A - 倉庫の在庫管理 / Warehouse Inventory Management Editorial
by
physics0523
初心者の方へ
- 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 入門用コンテンツです。
搬入・搬出作業を以下のように表現します。
- \(W_{P_i}\) に \(C_i\) 加算する。
こうすることで、この計算が終わった時点での \(W_{P_i}\) が倉庫 \(P_i\) の在庫となります。
全ての搬入・搬出が終わった後、全ての倉庫について \(W_i > L_i\) かどうかを判定することで容量超過している倉庫を数えることができます。
一連の実装は、 for 文や if 文などの組み合わせで実現できます。
実装例 (C++):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ll N,M;
cin >> N >> M;
vector<ll> W(N+5),L(N+5);
for(ll i=1;i<=N;i++){
cin >> W[i] >> L[i];
}
while(M--){
ll P,C;
cin >> P >> C;
W[P]+=C;
}
ll res=0;
for(ll i=1;i<=N;i++){
if(W[i]>L[i]){res++;}
}
cout << res << "\n";
return 0;
}
posted:
last update:
