版本比较
题解 UVA1316 【Supermarket】
正文
增加 4 行删除 4 行
57 行未改动5859606162626364656465666768697071727373747576777 行未改动57 行未改动 while(cin >> n) { ans = 0; memset(a, 0, sizeof(a)); priority_queue <cmp> que;
for(int i = 1; i <= n; ++i) scanf("%d %d", &a[i].val, &a[i].day); sort(a + 1, a + 1 + n);//按时间从小到大排序 sort(a + 1, a + 1 + n);//按时间从小到大排序
for(int i = 1; i <= n; ++i) { if(a[i].day > que.size()) que.push((cmp) {a[i].val}); else if(a[i].day == que.size() && a[i].val > que.top().val) { que.pop(); que.push((cmp) {a[i].val}); } }
while(!que.empty()) { ans += que.top().val; que.pop(); }7 行未改动