#include 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 _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; }