Cod sursa(job #2383004)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 18 martie 2019 22:19:43
Problema Euro Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;

ifstream fin("euro.in");
ofstream fout("euro.out");

const int NMax = 34567;

long long V[NMax + 5], DP[NMax + 5], N, T;

int main()
{
    fin >> N >> T;

    for(int i = 1; i <= N; i++)
    {
        fin >> V[i], V[i] += V[i - 1], DP[i] = V[i] * i - T;

        for(int j = 1; j < i; j++)
            DP[i] = max(DP[i], DP[j] + (V[i] - V[j]) * i - T);
    }
    fout << DP[N] << '\n';

    fin.close();
    fout.close();

    return 0;
}