标签:ann special needed nal show i++ travel desc span
Input
Output
Sample Input
4 4 4 5 2 11 5 15 10 25 10
Sample Output
2
Hint
#include<iostream> #include<stdio.h> #include<queue> #include<algorithm> #define maxn 1000005 using namespace std; struct Node { int dis; int fuel; }node[maxn]; priority_queue <int> fu; bool cmp(Node a,Node b) { if(a.dis!=b.dis) return a.dis>b.dis; } int main() { int n; cin>>n; for(int i=0;i<n;i++) { scanf("%d%d",&node[i].dis,&node[i].fuel); } sort(node,node+n,cmp); int p,l; cin>>l>>p; int t=0; bool flag=false; int res=0; for(int i=l;i>0;i--) { //cout<<i<<endl; //cout<<fu.top()<<endl<<endl; if(p>0) { p--; } else if(p==0) { for(t;t<n;t++) { if(node[t].dis<i) break; fu.push(node[t].fuel); } if(fu.empty()) { flag=true; break; } p=fu.top(); fu.pop(); res++; p--; } } if(!flag) { cout<<res<<endl; } else cout<<"-1"<<endl; return 0; }
标签:ann special needed nal show i++ travel desc span
原文地址:http://www.cnblogs.com/superxuezhazha/p/6360147.html