fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  4. #define nl "\n"
  5. #define xi first
  6. #define yi second
  7. #define vec vector
  8. #define vll vector<ll>
  9. #define vi vector<int>
  10. #define pb push_back
  11. #define dpp(arr,val) memset(arr,val,sizeof(arr))
  12. #define eb emplace_back
  13. #define all(a) a.begin(),a.end()
  14. #define rall(a) a.rbegin(),a.rend()
  15. #define pii pair<int,int>
  16. #define pll pair<ll,ll>
  17. #define sz(a) (int)(a).size()
  18. #define oom 0x3f
  19. #define ooi 0x3f3f3f3f
  20. #define ool 0x3f3f3f3f3f3f3f3f
  21.  
  22. typedef long long ll;
  23. typedef long double ld;
  24. typedef unsigned long long ull;
  25. using namespace std;
  26.  
  27. // template<typename T>
  28. // istream& operator>>(istream& in, vector<T>& v) {
  29. // for (auto& x : v)
  30. // in >> x;
  31. // return in;
  32. // }
  33. // template<typename T>
  34. // ostream& operator<<(ostream& out, vector<T>& v) {
  35. // for (auto& x : v)
  36. // out << x << ' ';
  37. // return out;
  38. // }
  39.  
  40. // constexpr double PI = 3.14159265359;
  41. // constexpr long long MOD = 1000000007;
  42. constexpr int NX = 2001;
  43. // const long long INF = 1e18;
  44. // int dx[] {-1, 1, 0, 0};
  45. // int dy[] {0, 0, -1, 1};
  46. int n;
  47. int arr[NX];
  48. ll dp[NX][NX];
  49. ll go(int l, int r, int day) {
  50. if (l > r) return 0;
  51. if (~dp[l][r]) return dp[l][r];
  52.  
  53. return dp[l][r] = max(go(l + 1, r, day + 1) + arr[l] * day, go(l, r - 1, day + 1) + arr[r] * day);
  54. }
  55.  
  56. void Ziad () {
  57. cin >> n;
  58. for (int i = 0; i < n; i++) cin >> arr[i];
  59. dpp(dp, -1);
  60.  
  61. cout << go(0, n - 1, 1) << nl;
  62. }
  63.  
  64. signed main() {
  65. // ﴾الَّذِينَ آمَنُوا وَتَطْمَئِنُّ قُلُوبُهُم بِذِكْرِ اللَّهِ ۗ أَلَا بِذِكْرِ اللَّهِ تَطْمَئِنُّ الْقُلُوبُ﴿
  66. IOS;
  67. #ifndef ONLINE_JUDGE
  68. freopen("Input.txt", "r", stdin);
  69. freopen("Output.txt", "w", stdout);
  70. freopen("Error.txt", "w", stderr);
  71. #endif
  72.  
  73. int ttt = 1;
  74. // cin >> ttt;
  75. while (ttt--) Ziad();
  76. return 0;
  77. }
Success #stdin #stdout 0.01s 34880KB
stdin
Standard input is empty
stdout
0