Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #ifndef ACMTUYO
  6. #define cin lala
  7. ifstream cin;
  8. #define cout coco
  9. ofstream cout;
  10. #endif
  11.  
  12. #define forsn(i, s, n) for(int i = int(s); i < int(n); ++i)
  13. typedef long long int ll;
  14. struct paciente{
  15. int tipo, timeA, timeB, id, minT;
  16. };
  17. bool CompA(const paciente & a, const paciente & b) { return a.timeB > b.timeB;};
  18. bool CompB(const paciente & a, const paciente & b) { return a.timeA > b.timeA;};
  19. pair<vector<int>,vector<int> > prueba(deque<paciente> A, deque<paciente> B, int & maxT)
  20. {
  21. sort(A.begin(),A.end(),CompA);
  22. sort(B.begin(),B.end(),CompB);
  23. vector<int> rA, rB;
  24. int tA = 0, tB = 0;
  25. while(A.size() || B.size())
  26. {
  27. //cout<<A.size()<<" - "<<B.size()<<endl;
  28. if(tA <= tB && A.size() || B.size() == 0)
  29. {
  30. auto p = A.front();
  31. tA = max(tA, p.minT);
  32. p.minT += p.timeA;
  33. tA += p.timeA;
  34. rA.push_back(p.id);
  35. if(A.front().tipo == 1) B.push_back(p);
  36. A.pop_front();
  37. }
  38. else
  39. {
  40. auto p = B.front();
  41. tB = max(tB, p.minT);
  42. p.minT += p.timeB;
  43. tB+=p.timeB;
  44. rB.push_back(p.id);
  45. if(B.front().tipo == 2) A.push_back(p);
  46. B.pop_front();
  47. }
  48. }
  49. maxT = max(tA,tB);
  50. return {rA,rB};
  51.  
  52. }
  53. paciente in[30];
  54. int N;
  55. vector<int> rA, rB;
  56. int bestT = 1e9;
  57. void Recursiva(int i, deque<paciente> & A, deque<paciente> & B)
  58. {
  59. cout<<i<<" / "<<N<<endl;
  60. if(i == N+1)
  61. {
  62. int t;
  63. pair<vector<int>,vector<int> > res = prueba(A,B,t);
  64. if(t < bestT) bestT = t, rA = res.first, rB = res.second;
  65. return;
  66. }
  67. if(in[i].tipo == 1)
  68. {
  69. A.push_back(in[i]);
  70. Recursiva(i+1,A,B);
  71. A.pop_back();
  72. }
  73. else if(in[i].tipo == 2)
  74. {
  75. B.push_back(in[i]);
  76. Recursiva(i+1,A,B);
  77. B.pop_back();
  78. }
  79. else
  80. {
  81. in[i].tipo = 1;
  82. A.push_back(in[i]);
  83. Recursiva(i+1,A,B);
  84. A.pop_back();
  85.  
  86. in[i].tipo = 2;
  87. B.push_back(in[i]);
  88. Recursiva(i+1,A,B);
  89. B.pop_back();
  90. }
  91.  
  92. }
  93. int main() {
  94. // assert(sqrte(1) == 1);
  95. // assert(sqrte(2) == 2);
  96. #ifndef ACMTUYO
  97. cin = ifstream("kth.in");
  98. cout = ofstream("kth.out");
  99. #endif
  100. cin>>N;
  101. cout<<"k"<<endl;
  102. for(int i = 1;i<=N;i++)
  103. {
  104. cin>>in[i].tipo>>in[i].timeA>>in[i].timeB;
  105. in[i].minT = 0;
  106. in[i].id = i;
  107. }
  108. cout<<"k"<<endl;
  109. deque<paciente> A,B;
  110. Recursiva(1,A,B);
  111. cout<<bestT<<endl;
  112. for(auto k : rA)cout<<k<<" ";
  113. cout<<endl;
  114. for(auto k : rB)cout<<k<<" ";
  115. cout<<endl;
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement