fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<ll, ll> ll2;
  7.  
  8. class BuildingTowers {
  9. public:
  10. ll k;
  11.  
  12. ll get_max(ll h1, ll h2, ll dist){
  13. if(h2 < h1) swap(h1, h2);
  14. ll l = h1, r = h2 + k*dist;
  15. while(l < r){
  16. ll mid = l + (r-l+1)/2;
  17. bool ok = ((abs(h1-mid)+k-1)/k + (abs(h2-mid)+k-1)/k <= dist); // ceil the result
  18. if(ok)
  19. l = mid;
  20. else
  21. r = mid-1;
  22. }
  23.  
  24. return max(l,h2);
  25. }
  26.  
  27. long long maxHeight(int N, int K, vector <int> x, vector <int> t) {
  28. vector<ll2> b;
  29. k = K;
  30. int m = (int)x.size();
  31. b.push_back(ll2(1,0));
  32. for(int i = 0; i < m; i++){
  33. b.push_back(ll2(x[i], t[i]));
  34. }
  35. m++;
  36.  
  37. for(int i = 1; i < m; i++){
  38. if(b[i-1].second < b[i].second)
  39. b[i].second = min(b[i].second, b[i-1].second + k*(b[i].first-b[i-1].first));
  40. }
  41. for(int i = m-2; i >= 0; i--){
  42. if(b[i+1].second < b[i].second)
  43. b[i].second = min(b[i].second, b[i+1].second + k*(b[i+1].first-b[i].first));
  44. }
  45.  
  46. ll ans = 0;
  47. for(int i = 1; i < m; i++)
  48. ans = max(ans, get_max(b[i].second, b[i-1].second, b[i].first-b[i-1].first));
  49.  
  50. ans = max(ans, ((ll)N - b[m-1].first)*k + b[m-1].second);
  51. return ans;
  52. }
  53. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i586-linux-gnu/4.9/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty