You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
698 B
C++

#include <cstdio>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
pair<int, int> fs[10005];
int main()
{
int n, L, P;
scanf("%d", &n);
priority_queue<int> heap;
for (int i = 0; i < n; i++) scanf("%d%d", &fs[i].first, &fs[i].second);
sort(fs, fs + n);
reverse(fs, fs + n);
scanf("%d%d", &L, &P);
int t = 0;
heap.push(P);
int index = 0;
while (L > 0 && !heap.empty())
{
t++;
int tmp = heap.top();
heap.pop();
L -= tmp;
while (index < n && L <= fs[index].first) heap.push(fs[index++].second);
}
printf("%d\n", L <= 0 ? t - 1 : -1);
return 0;
}