Advertisement
Dennnhhhickk

Untitled

Nov 8th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. // D.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <cmath>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14. typedef long double ld;
  15.  
  16. ull h[100000], v[100000];
  17. ll n, H, T;
  18.  
  19. bool check(ll t)
  20. {
  21. ll temp = t;
  22. for (int z = 0; z < T; z++)
  23. {
  24. for (int i = n - 1; i >= 0; i--)
  25. {
  26. if (h[i] <= t)
  27. t = max(h[i] - 1, t - v[i]);
  28. }
  29. if (t >= H)
  30. return 1;
  31. t += temp;
  32. }
  33. return 0;
  34. }
  35.  
  36. int main()
  37. {
  38. cin >> n >> H >> T;
  39. ll ans = H;
  40. for (int i = 0; i < n; i++)
  41. {
  42. cin >> h[i] >> v[i];
  43. //if (h[i] + v[i] >= H && h[i] <= H)
  44. ans += v[i];
  45. }
  46. ll l = 0, r = ans + 1;
  47. while (l + 1 < r)
  48. {
  49. ll m = (l + r) / 2;
  50. //cout << l << ' ' << r << ' ' << m << ' ' << check(m) << endl;
  51. //system("pause");
  52. if (check(m))
  53. r = m;
  54. else
  55. l = m;
  56. }
  57. cout << r << endl;
  58. system("pause");
  59. return 0;
  60. }
  61.  
  62. /*
  63. // ConsoleApplication9.cpp : Defines the entry point for the console application.
  64. //
  65.  
  66. //#include "stdafx.h"
  67. #include <iostream>
  68. #include <fstream>
  69. #include <cmath>
  70. #include <algorithm>
  71.  
  72. using namespace std;
  73.  
  74. typedef long long ll;
  75. typedef unsigned long long ull;
  76. typedef long double ld;
  77.  
  78. ull h[100000], v[100000];
  79. ll n, H, T;
  80.  
  81. bool check(ll t)
  82. {
  83. ll temp = t;
  84. for (int z = 0; z < T; z++)
  85. {
  86. for (int i = n - 1; i >= 0; i--)
  87. {
  88. if (h[i] <= t)
  89. t = max(h[i] - 1, t - v[i]);
  90. }
  91. if (t >= H)
  92. return 1;
  93. t += temp;
  94. }
  95. return 0;
  96. }
  97.  
  98. int main()
  99. {
  100. //cin >> n >> H >> T;
  101. n = 100000;
  102. H = 1000000000;
  103. T = H;
  104. ll ans = H;
  105. for (int i = 0; i < n; i++)
  106. {
  107. //cin >> h[i] >> v[i];
  108. h[i] = i + 1;
  109. v[i] = H;
  110. //if (h[i] + v[i] >= H && h[i] <= H)
  111. ans += v[i];
  112. }
  113. ll l = 0, r = ans + 1;
  114. while (l + 1 < r)
  115. {
  116. ll m = (l + r) / 2;
  117. //cout << l << ' ' << r << ' ' << m << ' ' << check(m) << endl;
  118. //system("pause");
  119. if (check(m))
  120. r = m;
  121. else
  122. l = m;
  123. }
  124. cout << r << endl;
  125. //system("pause");
  126. return 0;
  127. }
  128.  
  129.  
  130. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement