标签:
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
错把<span style="color:#ff0000;background-color: rgb(102, 255, 153);">int cmp(stu a,stu b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x; }</span>
<span style="color:#ff0000;background-color: rgb(102, 255, 153);">写成</span><pre name="code" class="cpp" style="font-size: 14px; line-height: 21px;"><span style="color:#ff0000;background-color: rgb(102, 255, 153);">int cmp(stu a,stu b){ if(a.x==b.x) return a.y>b.y; return a.x>b.x; }</span>
#include<stdio.h> #include<queue> #include<algorithm> using namespace std; struct stu{ int x,y; }aa[1000]; int cmp(stu a,stu b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x; } int main() { int n; while(scanf("%d",&n)!=EOF) { int i; // while() priority_queue<int ,vector<int>,greater<int> >s; for(i=0;i<n;i++) scanf("%d%d",&aa[i].x,&aa[i].y); int sum=0; sort(aa,aa+n,cmp); for(i=0;i<n;i++) { if(s.size()<aa[i].x) s.push(aa[i].y); else{ if(s.top()<aa[i].y) { sum+=s.top(); s.pop(); s.push(aa[i].y); } else sum+=aa[i].y; } } printf("%d\n",sum); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/l15738519366/article/details/47109021