标签:return amp bsp stream += bool include operator color
考试的时候上来就把题看错了qwq,还以为是线段覆盖呢,等到发现就晚了
教训:审题审题审题!
#include<algorithm> #include<iostream> #include<cstdio> #include<cmath> #include<queue> #include<vector> using namespace std; int n,ans; long long tail; struct in { long long a,b; }ter[150010]; priority_queue<in>qwq; bool cmp(in a,in b) { return a.b==b.b?a.a<b.a:a.b<b.b;//剩余时间是第一关键字。花销时间是第二关键字 } bool operator <(in a,in b) { return a.a<b.a; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld%lld",&ter[i].a,&ter[i].b); sort(ter+1,ter+1+n,cmp); for(int i=1;i<=n;i++) { if(tail+ter[i].a<=ter[i].b)//如果剩余时间足够 qwq.push(ter[i]),tail+=ter[i].a,ans++; else { in qaq=qwq.top(); qwq.pop(); tail-=qaq.a; if(qaq.a>ter[i].a)//如果堆顶值较大 qwq.push(ter[i]),tail+=ter[i].a;//则可以把这个元素放进去,因为所用时间更小 else qwq.push(qaq),tail+=qaq.a;//否则再放回去 } } printf("%d",ans); }
标签:return amp bsp stream += bool include operator color
原文地址:http://www.cnblogs.com/Loi-dfkdsmbd/p/7676766.html