标签:des style blog http color io os java ar
4 4 4 5 2 11 5 15 10 25 10
2
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 struct node{ 18 int x,y; 19 node(int a = 0,int b = 0){ 20 x = a; 21 y = b; 22 } 23 }; 24 node p[10010]; 25 bool cmp(const node &a,const node &b){ 26 return a.x < b.x; 27 } 28 priority_queue<int,vector<int>,less<int> >q; 29 int main() { 30 int n,L,pnow,pos = 0,ans = 0; 31 scanf("%d",&n); 32 for(int i = 0; i < n; i++) 33 scanf("%d %d",&p[i].x,&p[i].y); 34 35 scanf("%d %d",&L,&pnow); 36 for(int i = 0; i < n; i++) 37 p[i].x = L-p[i].x; 38 p[n].x = L; 39 p[n++].y = 0; 40 sort(p,p+n,cmp); 41 for(int i = 0; i < n; i++){ 42 int d = p[i].x - pos; 43 while( pnow - d < 0){ 44 if(q.empty()) { 45 puts("-1"); 46 return 0; 47 } 48 pnow += q.top(); 49 q.pop(); 50 ans++; 51 } 52 pnow -= d; 53 pos = p[i].x; 54 q.push(p[i].y); 55 } 56 printf("%d\n",ans); 57 return 0; 58 }
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/crackpotisback/p/3967177.html