Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- 2
- #include <algorithm>
- 3
-
- 4
- using namespace std;
- 5
-
- 6
- int main()
- 7
- {
- 8
- int n, a, nu = 0, np = 0, oa, p = 0, u = 0;
- 9
- cin >> n;
- 10
- cin >> oa;
- 11
- for(int i = 1; i < n; i++){
- 12
- cin >> a;
- 13
- if (a > oa){
- 14
- u = u + a - oa;
- 15
- p = 0;
- 16
- if (nu < u)
- 17
- nu = u;
- 18
- }
- 19
- if (a < oa){
- 20
- p = p + oa - a;
- 21
- u = 0;
- 22
- if (np < p)
- 23
- np = p;
- 24
- }
- 25
- oa = a;
- 26
- }
- 27
-
- 28
- cout << nu << " " << np << endl;
- 29
- return 0;
- 30
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement