# 优先队列的使用

#优先队列

#include<iostream>
#include<queue>
using namespace std;
typedef struct Node{
int x, y;
Node(int xx, int yy){x = xx; y = yy;}
bool operator < (Node const &a) const {
return x > a.x;
}
}Node;

int main(){
priority_queue<Node> list;
list.push(Node(5,3));
list.push(Node(1,1));
list.push(Node(3,3));
while(!list.empty()){
Node temp = list.top();
list.pop();
cout <<  "(" << temp.x << " " << temp.y << ") ";
}
return 0;
}


1 、重载运算符的时候只能重载 < 符号
2 、申明方法参数只有一个，而且是const 引用类型
3 、方法参数后面要加一个 const ，这是表明此方法不能修改类中的成员变量

#include<iostream>
#include<queue>
using namespace std;
int length;

int main(){
priority_queue<long long, vector<long long>, greater<long long> > list;
long long input;
cin >> length;
for(int i = 0; i < length; i++){
cin >> input;
list.push(input);
}

long long a, b, answer = 0;
while(list.size() > 1){
a = list.top(); list.pop();
b = list.top(); list.pop();
list.push(a + b);
}

return 0;
}


10
1 0
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 5
10 4
11 3

#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef struct Node{
int index;
int dist, fuel;
Node(){}
bool operator < (Node const &a) const {
return fuel < a.fuel;
}
}Node;
Node shuzu[10005];
int dist, fuel;
int jishu;

bool cmp(Node a, Node b){
return a.dist < b.dist;
}

int main(){
cin >> jishu;
for(int i = 0; i < jishu; i++)
cin >> shuzu[i].dist >> shuzu[i].fuel;
sort(shuzu, shuzu+jishu, cmp);
for(int i = 0; i < jishu; i++) shuzu[i].index = i;

cin >> dist >> fuel;
int i = jishu - 1;
int flag = 1;
priority_queue<Node> list;
while(dist-fuel > 0){
for(; i>=0 && shuzu[i].dist>=dist-fuel; i--){
if(shuzu[i].index == -1) continue;
list.push(shuzu[i]);
}

if(list.empty()) {flag = 0; break;}
Node temp = list.top();
list.pop();
if(dist >= temp.dist){
fuel = fuel - dist + temp.dist + temp.fuel;
dist = temp.dist;
}else{
fuel = fuel + temp.fuel;
}
shuzu[temp.index].index = -1;