You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1015 B
47 lines
1015 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
struct HuoWu {
|
|
string name;
|
|
int shouyi;
|
|
int count;
|
|
};
|
|
|
|
int main() {
|
|
//输入+输出重定向
|
|
//freopen("../x.in", "r", stdin);
|
|
//freopen("../x.out", "w", stdout);
|
|
|
|
int n, k;
|
|
cin >> n >> k;
|
|
unordered_map<string, HuoWu> _map;
|
|
for (int i = 0; i < n; ++i) {
|
|
HuoWu h;
|
|
cin >> h.name >> h.shouyi >> h.count;
|
|
_map[h.name] = h;
|
|
}
|
|
|
|
bool success = true;
|
|
int shouyi = 0;
|
|
for (int i = 0; i < k; ++i) {
|
|
HuoWu h;
|
|
cin >> h.name >> h.count;
|
|
if (_map[h.name].count >= h.count) {
|
|
_map[h.name].count = _map[h.name].count - h.count;
|
|
shouyi += _map[h.name].shouyi * h.count;
|
|
} else {
|
|
success = false;
|
|
cout << "-" << i + 1 << endl;
|
|
}
|
|
}
|
|
if (success) {
|
|
cout << shouyi << endl;
|
|
}
|
|
|
|
//关闭文件
|
|
//fclose(stdin);
|
|
//fclose(stdout);
|
|
return 0;
|
|
}
|