Advertisement
a53

curiosity2

a53
Dec 2nd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. # include <fstream>
  2. # include <algorithm>
  3. using namespace std;
  4.  
  5. #define NMax 100003
  6. #define inf 2000000000
  7.  
  8. int Xf, N, D, T, Max;
  9. pair <int, int> dp[NMax];
  10.  
  11. int main ()
  12. {
  13. ifstream f("curiosity2.in");
  14. ofstream g("curiosity2.out");
  15.  
  16. f >> Xf >> D >> T >> N;
  17. dp[1] = {0, -T};
  18. int st = 1, dr = 1;
  19.  
  20. for (int i = 1; i <= N; ++i){
  21.  
  22. int x, y, l;
  23. f >> x >> l; ///segmentul curent [x,y]
  24. y = x + l;
  25.  
  26. ///verific daca segmentul citit poate aduce o maximizare
  27. int nr_max = 0, dist_min = inf;
  28. for (; st <= dr; ++st) { ///
  29. if (dp[st].second + T + D > y) break;
  30.  
  31. int lung_seg = y - max (x, dp[st].second + T);
  32. int nr = lung_seg / D;
  33.  
  34. int dist = max (x, dp[st].second + T) + nr * D;
  35. nr += dp[st].first;
  36.  
  37. if (nr > nr_max || (nr == nr_max && dist_min > dist)) nr_max = nr, dist_min = dist;
  38. }
  39.  
  40. if (st > 1) --st;
  41.  
  42. if (Max < nr_max){
  43. dp[++dr] = {nr_max, dist_min};
  44. Max = nr_max;
  45. }
  46. }
  47.  
  48. g << Max << '\n';
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement