标签:之间 优先 out mat color put main blank max
直接中文
Descriptions
Input
Output
Sample Input
4 4 4 5 2 11 5 15 10 25 10
Sample Output
22
Hint
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #include <sstream> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #define Mod 1000000007 #define eps 1e-6 #define ll long long #define INF 0x3f3f3f3f #define MEM(x,y) memset(x,y,sizeof(x)) #define Maxn 100000+5 using namespace std; struct node { int dis;//距离 int value;//油 bool operator<(const node &c)const//按距离从大到小排序 { return dis>c.dis; } }; node a[Maxn]; priority_queue<int>q; int L,P,N; int main() { cin>>N; for(int i=0;i<N;i++) cin>>a[i].dis>>a[i].value; cin>>L>>P; sort(a,a+N);//排序 q.push(P); int ans=0,i=0; while(L>0&&!q.empty()) { ans++;//用了几个加油站 L-=q.top(); q.pop(); while(i<N&&L<=a[i].dis)//L<=a[i].dis,即进过加油站,存入队列 { q.push(a[i].value); i++; } } if(L>0) cout<<-1<<endl; else cout<<ans-1<<endl;//第一次的油是自己的 return 0; }
标签:之间 优先 out mat color put main blank max
原文地址:https://www.cnblogs.com/sky-stars/p/11332071.html