标签:
3 3 10 3 5 3 1 3 1 6 3 2 1 3 7 1 3 4 2 6 1 4 7 2 6 4 5 3 4
0 3 5
1 #include <queue> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 6 struct deliver 7 { 8 int ld, fs; 9 } num[2020]; 10 11 bool cmp(deliver ld,deliver fs) 12 { 13 if(ld.ld == fs.ld) 14 return ld.fs < fs.fs; 15 else 16 return ld.ld < fs.ld; 17 } 18 19 int main() 20 { 21 int i, n; 22 while(~scanf("%d", &n)) 23 { 24 priority_queue <int, vector<int>, greater<int> > q; 25 for(i=0; i<n; i++) 26 scanf("%d %d", &num[i].ld, &num[i].fs); 27 sort(num, num+n, cmp); 28 int sum = 0; 29 for(i=0; i<n; i++) 30 { 31 if(q.size() < num[i].ld) q.push(num[i].fs); 32 else 33 { 34 if(q.top() < num[i].fs) 35 { 36 sum += q.top(); 37 q.pop(); 38 q.push(num[i].fs); 39 } 40 else 41 sum += num[i].fs; 42 } 43 } 44 printf("%d\n", sum); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4684801.html