标签:
Description
Input
Output
Sample Input
4 4 4 5 2 11 5 15 10 25 10
Sample Output
2
Hint
1 #include <cstdio> 2 #include <algorithm> 3 #include <queue> 4 5 using namespace std; 6 const int MAXN = 10000 + 10; 7 int L, P, N; 8 struct node{ 9 int a, b; 10 }p[MAXN]; 11 12 bool cmp(const struct node p1, const struct node p2) 13 { 14 return p1.a < p2.a; 15 } 16 17 void solve() 18 { 19 p[N].a = L; 20 p[N].b = 0; 21 N++; 22 23 priority_queue<int> que; 24 int pos = 0, tank = P, ans = 0; 25 for(int i = 0; i != N; ++i) 26 { 27 int d = p[i].a - pos; 28 while(tank - d < 0) 29 { 30 if(que.empty()) 31 { 32 puts("-1"); 33 return; 34 } 35 tank += que.top(); 36 que.pop(); 37 ans++; 38 } 39 tank -= d; 40 pos = p[i].a; 41 que.push(p[i].b); 42 } 43 printf("%d\n", ans); 44 } 45 46 int main() 47 { 48 //freopen("in.txt", "r", stdin); 49 while(~scanf("%d" ,&N)) 50 { 51 for(int i = 0; i != N; ++i) 52 { 53 scanf("%d %d", &(p[i].a), &(p[i].b)); 54 //printf("%d %d\n", p[i].a, p[i].b); 55 } 56 57 scanf("%d %d", &L, &P); 58 for(int i = 0; i != N; ++i) 59 p[i].a = L - p[i].a; 60 sort(p, p+N, cmp); 61 62 solve(); 63 } 64 return 0; 65 }
标签:
原文地址:http://www.cnblogs.com/ya-cpp/p/4462007.html