Advertisement
erfanul007

Untitled

Jan 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int> pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define pb push_back
  14. #define pob pop_back
  15. #define mp make_pair
  16. #define ff first
  17. #define ss second
  18. #define loop1(i,n) for(int i=1; i<=int(n); i++)
  19. #define loop(i,y) for(int i=0; i<int(y); i++)
  20. #define rloop(i,y) for(int i=int(y); i>0; i--)
  21. #define rloop1(i,y) for(int i=int(y)-1; i>=0; i--)
  22. #define read() freopen("input.txt", "r", stdin)
  23. #define write() freopen("output.txt", "w", stdout)
  24. #define cspf(i) printf("Case %d: ", i)
  25. #define all(v) v.begin(),v.end()
  26. #define rall(v) v.rbegin(),v.rend()
  27. /// Constants
  28. #define eps 1e-9
  29. #define PI acos(-1.0) // 3.1415926535897932
  30.  
  31.  
  32. int main()
  33. {
  34. vi vt;
  35. int n,i,cnt=0,f1,cn1=0,mx=0;
  36. scanf("%d",&n);
  37. int a[n+5];
  38. loop1(i,n){
  39. scanf("%d",&a[i]);
  40. }
  41. cnt=0;
  42. for(i=1;i<n;i++){
  43. if(a[i+1]-a[i]==1){
  44. cnt++;
  45. continue;
  46. }
  47. if(cnt>0){
  48. if(a[i]==i)
  49. vt.pb(cnt);
  50. else
  51. vt.pb(cnt-1);
  52. cnt=0;
  53. }
  54. }
  55. if(cnt>0){
  56. if(a[n]==1000 || a[n]==n)
  57. vt.pb(cnt);
  58. else
  59. vt.pb(cnt-1);
  60. }
  61. if(vt.size()==0){
  62. printf("0\n");
  63. return 0;
  64. }
  65. sort(rall(vt));
  66. printf("%d\n",vt[0]);
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement