fork download
  1. /*
  2. Date: 22/11/2015
  3. Name:DAYSO9
  4. Link: http://l...content-available-to-author-only...u.vn/Problem/Details/4483
  5. Result: #28 - TLE
  6. */
  7. #include <iostream>
  8. #include <sstream>
  9. #include <cstdlib>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <utility>
  13. #include <map>
  14. #include <list>
  15. #include <deque>
  16.  
  17. using namespace std;
  18.  
  19. #define FOR(i,a,b) for(int i=a; i<=b; i++)
  20. #define Size first
  21. #define stt second
  22.  
  23. typedef long long LL;
  24. typedef pair<LL,LL> PLL;
  25.  
  26. LL n,A,G;
  27. deque<PLL> ball;
  28. vector<LL> track;
  29.  
  30. //Tim den cai Lon nhat < hon size, va chua bi an
  31. LL Find(LL L,LL R,LL size){
  32.  
  33. if(L > R){
  34. //cout<<"over : "<<L<<" - "<<R<<endl;
  35. return -1;
  36. }else{
  37. //Dieu kien tim thay la size[t] < size <= size[t+1]
  38. LL t = (L + R) / 2;
  39.  
  40. //cout<<L<<" - "<<R<<" - "<<t<<endl;
  41.  
  42. if(ball[t].Size < size){
  43. //Neu nho hon
  44. //Kiem tra xem co phai ko, neu khong phai thi tim len phia tren
  45. if(t == ball.size()-1){
  46. return t;
  47. }else{
  48. if(size <= ball[t+1].Size)
  49. {
  50. return t;
  51. }else{
  52. //Tim tiep ve phia tren
  53. return Find(t+1,R,size);
  54. }
  55.  
  56.  
  57. }
  58. }else{
  59. //Neu hien tai dang lon hon thi tim ve phia truoc
  60. return Find(L,t-1,size);
  61. }
  62. }
  63. }
  64.  
  65. int main()
  66. {
  67.  
  68. cin>>n>>A>>G;
  69. LL s;
  70. if(A > G)
  71. {
  72. cout<<0<<endl;
  73. return 0;
  74. }
  75. FOR(i,0,n-1)
  76. {
  77. cin>>s;
  78. ball.push_back(make_pair(s,i+1));
  79. }
  80.  
  81. sort(ball.begin(),ball.end());
  82. LL index = -1;
  83. do{
  84. index = Find(0,ball.size()-1,A);
  85.  
  86. if(index != -1){
  87.  
  88. A += ball[index].Size;
  89. track.push_back(ball[index].stt);
  90. ball.erase(ball.begin() + index);
  91.  
  92. if(A > G){
  93. cout<<track.size()<<endl;
  94. FOR(i,0,track.size()-1)
  95. cout<<track[i]<<" ";
  96. return 0;
  97. }
  98. }
  99. }while(index != -1);
  100. cout<<-1<<endl;
  101. return 0;
  102. }
  103.  
Success #stdin #stdout 0s 3428KB
stdin
3 10 15
1 5 10
stdout
2
2 3