/* -*- coding: utf-8 -*- * * 3302.cc: No.3302 Sense Battle - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 5000; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N], bs[MAX_N]; ll dp[MAX_N + 1][MAX_N + 1]; /* subroutines */ inline void setmax(ll &a, ll b) { if (a < b) a = b; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i); for (int i = n - 1; i >= 0; i--) for (int j = 0; i + j < n; j++) { setmax(dp[i][j], dp[i + 1][j] + (ll)as[i] * j); setmax(dp[i][j + 1], dp[i + 1][j] + bs[i]); } ll maxd = *max_element(dp[0], dp[0] + n + 1); printf("%lld\n", maxd); return 0; }