• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Aug 14th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <iostream>
3. #include <cstdio>
4. #include <set>
5. #include <vector>
6. #include <assert.h>
7. #include <algorithm>
8.
9.
10. using namespace std;
11.
12.
13. int main()
14. {
15.     int n;
16.     cin>>n;
17.
18.     vector< int> sf(n+2);
19.     for(int i = 0; i<n; i++)
20.     {
21.         scanf("%d",&sf[i]);
22.     }
23.
24.     int l = 0;
25.     int r = 0;
26.     bool kuda = true;
27.     if(sf[r] > sf[r+1])
28.     {
29.         kuda = false;
30.     }
31.     r++;
32.     if(sf[r] == sf[r-1])
33.     {
34.         l= r;
35.
36.     }
37.
38.     int ans =1;
39.     if(n  != 1)
40.         ans = max(r-l+1,ans);
41.
42.     while(r < n -1)
43.     {
44.         if(sf[r]  > sf[r+1] && kuda)
45.         {
46.             kuda = false;
47.             r++;
48.         }
49.         else if(sf[r]  < sf[r+1] && !kuda )
50.         {
51.             kuda = true;
52.             r++;
53.         }
54.         else
55.         {
56.
57.             //   cout<<sf[r]<<" "<<sf[r+1]<<" "<<r<<endl;
58.             kuda = true;
59.             if(sf[r] >= sf[r+1])
60.             {
61.                 kuda = false;
62.             }
63.             l = r ;
64.             r++;
65.
66.         }
67.         //    cout<<l<<" "<<r<<" "<<sf[l]<<" "<<sf[r]<<endl;
68.         if(sf[r] == sf[r-1])
69.         {
70.             l= r;
71.             //  cout<<r<<endl;
72.         }
73.         ans = max(r-l+1,ans);
74.
75.
76.     }
77.     if(n!=1)
78.         ans = max(r-l+1,ans);
79.     cout<<ans<<endl;
80.
81.     return 0;
82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top