fork download
  1. #include<bits/stdc++.h>
  2. #define ull unsigned long long
  3. #define ll long long
  4. #define all(x) x.begin(), x.end()
  5. using namespace std;
  6. const int maxn = 1e5 + 1;
  7. ll A[3001][3001];
  8. map<pair<int, int>, int> mp;
  9. int main() {
  10. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11. int n;
  12. ll x;
  13. cin >> n;
  14. for (int i = 1; i <= n; ++i) {
  15. cin >> x;
  16. A[0][i] = x;
  17. A[n - i + 1][0] = x;
  18. }
  19. for (int i = 1; i <= n; ++i) {
  20. for (int j = 1; j <= n; ++j) {
  21. A[i][j] = A[0][j] * A[i][0];
  22. }
  23. }
  24. int j = n;
  25. for (int i = 1; i <= n; ++i) {
  26. mp[make_pair(i, j)] = true;
  27. --j;
  28. }
  29. ll res = INT_MIN;
  30. for (int i = 1; i < n; ++i) {
  31. for (int j = 1; j < n; ++j) {
  32. int fakeI = i, fakeJ = j;
  33. ll sum = 0;
  34. while (mp[make_pair(fakeI, fakeJ)] == false && fakeI < n && fakeJ < n) {
  35. sum += A[fakeI][fakeJ];
  36. ++fakeI;
  37. ++fakeJ;
  38. }
  39. res = max(res, sum);
  40. }
  41. }
  42. cout<<res;
  43. }
  44.  
Success #stdin #stdout 0.01s 5284KB
stdin
5 
3 2 -9 1 -8
stdout
72