Pagini recente » Cod sursa (job #1617660) | Cod sursa (job #2343285) | Cod sursa (job #743111) | Cod sursa (job #1835376) | Cod sursa (job #603644)
Cod sursa(job #603644)
# include <cstdio>
const char *FIN = "euro.in", *FOU = "euro.out";
const int MAX = 34569;
int N, T, V[MAX], S[MAX];
struct vec {
int x, y;
vec () {} ;
vec (int a, int b) {
x = a, y = b;
};
} ;
vec A[MAX];
long long dp[MAX];
inline void getmax (long long &A, long long B) {
A = A > B ? A : B;
}
int main (void) {
freopen (FIN, "r", stdin);
scanf ("%d %d", &N, &T);
for (int i = 1; i <= N; ++i) {
scanf ("%d", V + i);
S[i] = S[i - 1] + V[i];
if (A[A[0].x].x < 0 || A[0].x == 0) ++A[0].x;
A[A[0].x] = vec (A[A[0].x].x + V[i], i);
}
for (int i = 1; i <= A[0].x; ++i) {
dp[i] = -0x3f3f3f3f3f3f3fLL;
for (int j = i; j + 1 && (i - j) * (i - j) <= 1000 + T; --j)
getmax (dp[i], dp[j] + (S[A[i].y] - S[A[j].y]) * 1LL * A[i].y - T);
}
fprintf (fopen (FOU, "w"), "%lld", dp[A[0].x]);
}