题目链接:https://ac.nowcoder.com/acm/contest/903/K
解题心得:水题,跟着模拟就行了,不知道会不会出现制作的菜的素材在上面列表上没出现过。注意超过int了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 10100;
ll n, m;
string s[maxn];
map <string, ll> tot_cnt, lack_cnt;
void init() {
cin>>n>>m;
for(ll i=1;i<=n;i++) {
ll cnt;
cin >> s[i] >> cnt;
tot_cnt[s[i]] = cnt;
}
}
bool puts_no() {
map <string, ll> :: iterator iter;
string temp;
for(iter=lack_cnt.begin();iter!=lack_cnt.end();iter++) {
temp = iter->first;
ll cnt = iter->second;
if(cnt > tot_cnt[temp]) {
puts("NO");
return true;
}
}
return false;
}
int main() {
// freopen("1.in.txt", "r", stdin);
init();
while(m--) {
ll q; scanf("%lld", &q);
for(ll i=1;i<=q;i++) {
ll cnt;
string temp;
cin>>temp>>cnt;
lack_cnt[temp] += cnt;
}
}
if(puts_no()) return 0;
puts("YES");
map <string, ll> :: iterator iter;
for(ll i=1;i<=n;i++) {
if(tot_cnt[s[i]] - lack_cnt[s[i]] != 0)
cout<<s[i]<< " "<<tot_cnt[s[i]] - lack_cnt[s[i]] << endl;
}
}