1 条题解
-
0
C++ :
#include <cstdio> #include <unordered_map> #include <string> using namespace std; struct G { int gain; long long rest; }; static char w[64]; int main(){ int n, k; if(scanf("%d %d", &n, &k) != 2) return 0; unordered_map<string, G> mp; for(int i = 0; i < n; i++){ int g, c; scanf("%s %d %d", w, &g, &c); G t; t.gain = g; t.rest = c; mp[(string)w] = t; } long long total = 0; for(int i = 1; i <= k; i++){ int q; scanf("%s %d", w, &q); G &t = mp[(string)w]; if(t.rest < q){ /* 库存不足:第一个失败的订单 */ printf("-%d\n", i); return 0; } t.rest -= q; total += (long long)t.gain * q; /* 收益*数量 可能超 int */ } printf("%lld\n", total); return 0; }
- 1
信息
- ID
- 2612
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者