Advertisement
Ahmed_Negm

Untitled

Mar 26th, 2023
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.txt", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  33. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  34.  
  35.  
  36.  
  37.  
  38. void solve(){
  39.   ll n; cin>>n;
  40.   vector<ll>v(n);
  41.     for(int i=0;i<n;i++)cin>>v[i];
  42.     vector<ll>part(n+1);
  43.     for(int i=0;i<n;i++){
  44.         part[i]+=1;
  45.         ll x = min(n,i+v[i]);
  46.         part[x]-=1;
  47.     }
  48.    
  49.     for(int i=1;i<n;i++){
  50.         part[i]+=part[i-1];
  51.     }
  52.  
  53.     ll mx = -1,cnt = 0,pos = -1;
  54.     for(ll i=0;i<n;i++){
  55.         if(part[i]==1){
  56.             cnt++;
  57.         }
  58.         else{
  59.             if(cnt > mx and cnt){
  60.                 mx = cnt;
  61.                 pos = i-cnt+1;
  62.             }
  63.             cnt = 0;
  64.         }
  65.     }
  66.    
  67.     if(cnt > mx and cnt){
  68.         mx = cnt;
  69.         pos = n-cnt+1;
  70.     }
  71.  
  72.    
  73.     if(pos == -1){
  74.         cout<<-1<<nl;
  75.     }
  76.     else{
  77.         cout<<mx<<" "<<pos<<nl;
  78.     }
  79.  
  80.  
  81.  
  82. }
  83.  
  84. int main(){
  85.     Fast_IO();
  86. int t =1;
  87. //cin>>t;
  88. while(t--){
  89. solve();
  90. }
  91. return 0;
  92. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement