Advertisement
a53

tunel

a53
Jul 14th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. /// Implementation : Adrian Panaete
  3. using namespace std;
  4. ifstream f("tunel.in");
  5. ofstream g("tunel.out");
  6. const int maxTunnelLength = 50002;
  7. int speed[maxTunnelLength];
  8. int
  9. numberOfCars,numberOfGroups,
  10. tunnelLength,
  11. carPosition,carDistance,carSpeed,
  12. groupSpeed,groupDistance,
  13. groupSize,maxSize;
  14. int main()
  15. {
  16. f>>numberOfCars>>tunnelLength;
  17. for(; numberOfCars; numberOfCars--)
  18. {
  19. f>>carPosition;
  20. carDistance=tunnelLength-carPosition;
  21. f>>speed[carDistance];
  22. }
  23. groupSpeed=101;
  24. groupDistance=0;
  25. groupSize=0;
  26. for(carDistance=1; carDistance<=50000; carDistance++)
  27. if(speed[carDistance])
  28. {
  29. carSpeed=speed[carDistance];
  30. ///stay with this group <=>
  31. ///carTimeToExit >= groupTimeToExit <=>
  32. ///carDistance/carSpeed >= groupDistance/groupSpeed <=>
  33. ///groupSpeed*carDistance >= carSpeed*groupDistance
  34. if(groupSpeed*carDistance<=carSpeed*groupDistance)
  35. groupSize++;
  36. else
  37. {
  38. numberOfGroups++;
  39. groupSize=1;
  40. groupSpeed=carSpeed;
  41. groupDistance=carDistance;
  42. }
  43. maxSize=max(maxSize,groupSize);
  44. }
  45. g<<numberOfGroups<<'\n';
  46. g<<maxSize<<'\n';
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement