标签:
4 4 4 5 2 11 5 15 10 25 10
2
1 #include <iostream> 2 #include <stdio.h> 3 #include <queue> 4 #include <vector> 5 #include <algorithm> 6 using namespace std; 7 struct Node{int L,P;}; 8 struct CMP_L{bool operator()(Node a,Node b){return a.L<b.L;}}; 9 struct CMP_P{bool operator()(Node a,Node b){return a.P<b.P;}}; 10 int main() 11 { 12 int N,i,j,L,P,Begin,Dic,Times; 13 Node NUM; 14 while(scanf("%d",&N)!=EOF) 15 { 16 priority_queue<Node,vector<Node>,CMP_L>ID_L; 17 priority_queue<Node,vector<Node>,CMP_P>ID_P; 18 for(i=0;i<N;i++) 19 { 20 scanf("%d%d",&NUM.L,&NUM.P); 21 ID_L.push(NUM); 22 } 23 scanf("%d%d",&L,&P); 24 NUM.L=0;NUM.P=0; 25 ID_L.push(NUM); 26 27 Begin=L;Times=0; 28 while(!ID_L.empty()) 29 { 30 NUM=ID_L.top();ID_L.pop(); 31 Dic=Begin-NUM.L; 32 while(P-Dic<0) 33 { 34 if(ID_P.empty()) 35 { 36 Times=-1; 37 break; 38 } 39 P+=ID_P.top().P; 40 ID_P.pop(); 41 Times++; 42 } 43 if(Times==-1)break; 44 P-=Dic; 45 Begin=NUM.L; 46 ID_P.push(NUM); 47 } 48 printf("%d\n",Times); 49 } 50 return 0; 51 }
标签:
原文地址:http://www.cnblogs.com/LWF5201314614/p/4693298.html