Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. 2
  3. #include <algorithm>
  4. 3
  5. 4
  6. using namespace std;
  7. 5
  8. 6
  9. int main()
  10. 7
  11. {
  12. 8
  13. int n, a, nu = 0, np = 0, oa, p = 0, u = 0;
  14. 9
  15. cin >> n;
  16. 10
  17. cin >> oa;
  18. 11
  19. for(int i = 1; i < n; i++){
  20. 12
  21. cin >> a;
  22. 13
  23. if (a > oa){
  24. 14
  25. u = u + a - oa;
  26. 15
  27. p = 0;
  28. 16
  29. if (nu < u)
  30. 17
  31. nu = u;
  32. 18
  33. }
  34. 19
  35. if (a < oa){
  36. 20
  37. p = p + oa - a;
  38. 21
  39. u = 0;
  40. 22
  41. if (np < p)
  42. 23
  43. np = p;
  44. 24
  45. }
  46. 25
  47. oa = a;
  48. 26
  49. }
  50. 27
  51. 28
  52. cout << nu << " " << np << endl;
  53. 29
  54. return 0;
  55. 30
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement