fork download
  1. /*
  2. date:
  3. site: NTU
  4. name: AGAR
  5. link: http://l...content-available-to-author-only...u.vn/Problem/Details/4479
  6. */
  7. #include <iostream>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <utility>
  11. #include <list>
  12.  
  13. using namespace std;
  14.  
  15. #define FOR(i,a,b) for(LL i=a; i<=b; i++)
  16. #define Size first
  17. #define Stt second
  18.  
  19. typedef long long LL;
  20. typedef pair<LL,LL> Ball;
  21. typedef vector<Ball>::iterator IT;
  22.  
  23. bool operator<(const Ball& truoc,const Ball& sau)
  24. {
  25. return truoc.Size < sau.Size;
  26. }
  27.  
  28. vector<Ball> a,smaller,bigger;
  29. vector<LL> track;
  30.  
  31. int main()
  32. {
  33. LL n,A,B,x;
  34.  
  35. cin>>n>>A>>B;
  36.  
  37. if(A > B)
  38. {
  39. cout<<"0"<<endl;
  40. return 0;
  41. }
  42.  
  43. FOR(i,1,n)
  44. {
  45. cin>>x;
  46. a.push_back(make_pair(x,i));
  47. }
  48.  
  49. sort(a.begin(),a.end());
  50.  
  51. // for(auto x : a)
  52. // cout<<x.Size<<" - "<<x.Stt<<endl;
  53. // cout<<endl;
  54.  
  55. for(int i=0; i<a.size() && a[i].Size < A; i++)
  56. smaller.push_back(a[i]);
  57.  
  58. for(int i=a.size()-1; i>=0 &&a[i].Size >= A; i--)
  59. bigger.push_back(a[i]);
  60.  
  61. while(!smaller.empty())
  62. {
  63. //Lay phan tu lon nhat trong day be ra
  64. if(smaller.back().Size >= A)
  65. {
  66. //khong con phan tu nao co the an duoc
  67. break;
  68. }else{
  69. A += smaller.back().Size;
  70. track.push_back(smaller.back().Stt);
  71. smaller.pop_back();
  72.  
  73. //Update la 2 day
  74. while(bigger.empty() == false && bigger.back().Size < A)
  75. {
  76. smaller.push_back(bigger.back());
  77. bigger.pop_back();
  78. }
  79.  
  80. }
  81.  
  82. if(A > B){
  83. cout<<track.size()<<endl;
  84. for(auto x : track)
  85. cout<<x<<" ";
  86. return 0;
  87. }
  88.  
  89. }
  90. cout<<"-1"<<endl;
  91. return 0;
  92. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
10 20 100
15 2 25 23 23 5 35 33 38 14
compilation info
prog.cpp: In function 'int main()':
prog.cpp:84:13: error: 'x' does not name a type
    for(auto x : track)
             ^
prog.cpp:86:4: error: expected ';' before 'return'
    return 0;
    ^
prog.cpp:86:4: error: expected primary-expression before 'return'
prog.cpp:86:4: error: expected ';' before 'return'
prog.cpp:86:4: error: expected primary-expression before 'return'
prog.cpp:86:4: error: expected ')' before 'return'
stdout
Standard output is empty