-
Notifications
You must be signed in to change notification settings - Fork 0
/
2431.cpp
43 lines (40 loc) · 804 Bytes
/
2431.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
struct Node{int dis,fuel;} zhan[10008];
priority_queue<int> q;
bool cmp(const Node &a,const Node &b)
{
return a.dis>b.dis;
}
int main()
{
int N,L,P;
cin >> N;
for(int i=1;i<=N;++i)
cin >> zhan[i].dis >> zhan[i].fuel;
zhan[++N]=(Node){0,0};
cin >> L >> P;
sort(zhan+1,zhan+N+1,cmp);
int ans=0;
for(int i=1;i<=N;++i)
{
while(L-P>zhan[i].dis)
{
if(q.empty())
{
cout << -1 << endl;
return 0;
}
P+=q.top();
q.pop();
++ans;
}
P-=L-zhan[i].dis;
L=zhan[i].dis;
q.push(zhan[i].fuel);
}
cout << ans << endl;
return 0;
}