Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的代码还不错吧。 就是stl耗时有点长呀。。。。。#define F(i,m,n) for (int i = m; i < n; ++i) std::vector<int> prods[10002]; std::multiset<int> sells; int main() { int N, p, d, maxd; while (scanf("%d", &N) == 1) { memset(prods, 0, sizeof(prods)); maxd = -1; F(i, 0, N) { scanf("%d %d", &p, &d); prods[d].push_back(p); if (d > maxd) maxd = d; } int sum = 0; sells.clear(); for (int i = maxd; i > 0; --i) { F(j, 0, prods[i].size()) sells.insert(prods[i][j]); if (!sells.size()) continue; sum += *(--sells.end()); sells.erase(--sells.end()); } printf("%d\n",sum); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator