Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define TASK "TESTCODE"
- using namespace std;
- const int N = 1e5;
- int index[N + 1], n, a[N + 1], res = 0;
- void read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++ i)
- {
- cin >> a[i];
- index[a[i]] = i;
- }
- }
- void solve()
- {
- index[0] = 1e9;
- for (int i = 1; i <= n; ++ i)
- {
- res = max(res, index[i] - index[i - 1]);
- index[i] = min(index[i], index[i - 1]);
- }
- cout << res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- //freopen(TASK".INP", "r", stdin);
- //freopen(TASK".OUT", "w", stdout);
- int t = 1;
- bool typetest = false;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- read();
- solve();
- }
- }
Add Comment
Please, Sign In to add comment