forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1062A.cpp
More file actions
31 lines (28 loc) · 741 Bytes
/
Copy path1062A.cpp
File metadata and controls
31 lines (28 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
int n;
cin >> n;
int arr[n], diff[n][n];
memset(diff, 0, sizeof(diff));
FOR(i, 0, n) {
cin >> arr[i];
FOR(j, 0, i)
diff[j][i] = arr[i] - arr[j];
}
int ans = 0;
FOR(i, 0, n) {
int tmpmaks = 0;
FOR(j, 0, n) {
if (diff[i][j] == abs(i-j) && diff[i][j]) {
int tmpdiv = diff[i][j]-1;
if (arr[i] == 1 && arr[j] == j+1 || arr[j] == 1000) tmpdiv++;
tmpmaks = max(tmpmaks, tmpdiv);
}
}
ans = max(ans, tmpmaks);
}
cout << ans << '\n';
}