Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. inline void prep ()
  5. {
  6. cin.tie (0);
  7. cin.sync_with_stdio (0);
  8. };
  9.  
  10. int mod = 1000000007;
  11.  
  12. long long mymod(long long num){
  13. if (num< 0){
  14. if (mod == 1){
  15. return 0;
  16. }
  17. return mod-abs(num)%mod;
  18. }else{
  19. return num%mod;
  20. }
  21. }
  22.  
  23. double eps = .0000000001;
  24.  
  25. int main ()
  26. {
  27. prep ();
  28. while (true){
  29. int n;
  30. cin >> n;
  31. if (n == 0){
  32. break;
  33. }
  34. int nums[n];
  35. for (int i=0; i<n; i++){
  36. cin >> nums[i];
  37. }
  38.  
  39. int l = 0;
  40. int r = nums[n-1]*20;
  41. int mid = (l+r)>>1;
  42. vector<int> bestlst = {nums[n-1]};
  43. int lastbest = 0;
  44. while (l <= r){
  45. mid = (l+r)>>1;
  46. int startfrom = mid/20+1;
  47. int strt = 0;
  48. bool can = true;
  49. while (strt < n && nums[strt] <= startfrom){
  50. strt++;
  51. }
  52. if (strt == n){
  53. r = mid-1;
  54. continue;
  55. }
  56.  
  57. int curroom = nums[strt];
  58. int stops = 0;
  59. vector<int> curlst;
  60.  
  61. while (curroom <= nums[n-1] && can){
  62. // go up rooms until room can't reach strt with time
  63. // mark that room as a stop
  64. // go up num until you reach a floor that can't reach the last placed stop
  65. curroom = nums[strt];
  66. while (curroom <= nums[n-1]){
  67. int timee = stops*10+4*(curroom-1)+20*(curroom-nums[strt]);
  68.  
  69. if (timee > mid){
  70. if (curroom == nums[strt]){
  71. can = false;
  72. break;
  73. }
  74. curlst.push_back(curroom-1);
  75. stops++;
  76. break;
  77. }
  78. curroom++;
  79. }
  80. if (!can){
  81. break;
  82. }
  83. bool chose = false;
  84. for (int i=strt; i<n; i++){
  85. if (nums[i] > curroom-1){
  86. int timee = max(0, stops-1)*10+4*(curroom-2)+20*(nums[i]-(curroom-1));
  87. if (timee > mid){
  88. strt = i;
  89. chose = true;
  90. break;
  91. }
  92. }
  93. }
  94. if (!chose){
  95. break;
  96. }
  97. }
  98. if (!can){
  99. l = mid+1;
  100. }else{
  101. r = mid-1;
  102. lastbest = mid;
  103. curlst.push_back(nums[n-1]);
  104. bestlst = curlst;
  105. }
  106. }
  107. cout << lastbest << '\n';
  108. cout << bestlst.size() <<" ";
  109. for (int i=0; i<bestlst.size(); i++){
  110. cout << bestlst[i];
  111. if (i != bestlst.size()-1){
  112. cout << " ";
  113. }
  114. }
  115. cout << '\n';
  116. }
  117. return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement