标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7575 | Accepted: 2234 |
Description
Input
Output
Sample Input
4 4 4 5 2 11 5 15 10 25 10
Sample Output
2
#include<iostream> #include<queue> #define MAX 10001 using namespace std; int N, L, P; //int a[MAX], b[MAX]; typedef struct { int a, b; }fuelstation; bool cmp(fuelstation x, fuelstation y){ return x.a > y.a; } fuelstation fuel[MAX]; void solve(){ cin >> N; for (int i = 0; i < N; i++){ //cin >> a[i] >> b[i]; cin >> fuel[i].a >> fuel[i].b; } cin >> L >> P; fuel[N].a = 0; fuel[N].b = 0; N++; sort(fuel, fuel + N, cmp); priority_queue<int> que; int time = 0, pos = L, tank = P; for (int i = 0; i < N; i++){ int d = pos - fuel[i].a; while (tank - d < 0){ if (que.empty()){ cout << "-1" << endl; return; } tank += que.top(); que.pop(); time++; } tank -= d; pos = fuel[i].a; que.push(fuel[i].b); } cout << time << endl; } int main() { solve(); system("pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/littlehoom/p/4202878.html