标签:des style blog http color java os io
4 50 2 10 1 20 2 30 1 7 20 1 2 1 10 3 100 2 8 2 5 20 50 10
80 185
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #include <queue> 10 #define LL long long 11 #define INF 0x3f3f3f 12 using namespace std; 13 struct node { 14 int px,dx; 15 } p[10010]; 16 bool cmp(const node &x,const node &y) { 17 return (x.dx < y.dx || x.dx == y.dx&&x.px > y.px); 18 } 19 priority_queue<int,vector<int>,greater<int> >q; 20 int main() { 21 int n,i,j; 22 while(~scanf("%d",&n)) { 23 for(i = 0; i < n; i++) 24 scanf("%d %d",&p[i].px,&p[i].dx); 25 sort(p,p+n,cmp); 26 while(!q.empty()) q.pop(); 27 LL ans = 0; 28 for(i = 0; i < n; i++) { 29 if(q.size() == p[i].dx) { 30 if(q.top() < p[i].px) { 31 ans += p[i].px - q.top(); 32 q.pop(); 33 q.push(p[i].px); 34 } 35 } else { 36 q.push(p[i].px); 37 ans += p[i].px; 38 } 39 } 40 printf("%lld\n",ans); 41 } 42 return 0; 43 }
BNUOJ 1575 Supermarket,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/crackpotisback/p/3879167.html