fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  4. #define ll long long
  5. #define vll vector<long long>
  6. #define pii pair<int,int>
  7. #define vpii vector<pair<int,int>>
  8. #define pll pair<long long ,long long >
  9. #define pb push_back
  10. #define ff first
  11. #define sec second
  12. #define SORT(a) sort(a.begin(),a.end())
  13. #define m_p make_pair
  14. #define all(x) (x.begin(),x.end())
  15. #define sz(v) ((int)(v.size()))
  16. #define INF 1e9+7
  17. typedef vector<int> vi ;
  18. const int MOD=1e9 +7 ;
  19. int size=10000000;
  20.  
  21.  
  22. int main(){
  23.  
  24. fast;
  25. int n ;
  26. cin>>n;
  27. vector<int> v(n);
  28. for(int i=0 ;i<n;i++){
  29. cin>>v[i];
  30. }
  31. int mx=0;
  32. vector<pii> store;
  33. int start=0; int end=0;
  34.  
  35. for(int i=0;i<n-1;i++){
  36.  
  37. if( v[i]<v[i+1]){
  38. end++;
  39. }
  40. else{
  41. store.pb(make_pair(start,end));
  42. start=end+1;
  43. end=start;
  44. }
  45. }
  46. if(v[n-1]>v[n-2]) store.pb(make_pair(start,end));
  47. mx=max(mx, store[0].sec - store[0].ff + 1 );
  48.  
  49. for(int i=0;i<store.size();i++){
  50. if(i+1<store.size() && store[i+1].ff-1==store[i].sec && v[store[i].sec-1]<v[store[i+1].ff]){
  51. mx=max(mx,store[i+1].sec-store[i].ff);
  52. }
  53. else if(i+1<store.size()&&store[i+1].ff-1==store[i].sec&&v[store[i].sec]<v[store[i+1].ff+1]){
  54. mx=max(mx,store[i].sec+store[i+1].sec-store[i+1].ff-store[i].ff+1);
  55. }
  56. else{
  57. mx=max(mx, store[i].sec - store[i].ff + 1 );
  58. }
  59. }
  60.  
  61. /*
  62. for(int i=0;i<store.size();i++){
  63. cout<<store[i].ff<<" "<<store[i].sec<<endl;
  64. }
  65.   */
  66.  
  67. cout<<mx<<endl;
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 4524KB
stdin
4
2 3 1 4
stdout
3