Advertisement
a53

curiosity

a53
Dec 6th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. # define NMax 100003
  5.  
  6. vector <int> X[4];
  7. int cost[4][NMax], cost_optim[4];
  8. int Xs, Xf, C, n;
  9.  
  10. int main()
  11. {
  12. freopen("curiosity.in", "r", stdin);
  13. freopen("curiosity.out","w", stdout);
  14.  
  15. scanf("%d%d%d%d", &Xs, &Xf, &C, &n);
  16.  
  17. for(int i = 0; i < n; ++i){
  18. int t, x;
  19. scanf("%d%d", &t, &x);
  20.  
  21. if(x >= Xf)
  22. continue;
  23.  
  24. for(int j = 1; j <= t; ++j)
  25. X[j].push_back(x);
  26. }
  27.  
  28. for(int t = 1; t <= 3; ++t){
  29.  
  30. X[t].push_back(Xf);
  31.  
  32. for(int j = X[t].size() - 2; j >= 0; j--) /// ultima pozitie inainte de Xf
  33. cost[t][j] = cost[t][j + 1] + max(0, (X[t][j + 1] - X[t][j]) - C);
  34. }
  35.  
  36. for(int t = 1; t <= 3; ++t) {
  37.  
  38. int x = lower_bound(X[t].begin(), X[t].end(), Xs) - X[t].begin();
  39.  
  40. cost_optim[t] = cost[t][x] + max(0, X[t][x] - Xs - C);
  41. }
  42.  
  43. if(cost_optim[1] != 0)
  44. printf("-1\n");
  45. else
  46. printf("%d %d\n", cost_optim[2], cost_optim[3] - cost_optim[2]);
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement