Cod sursa(job #3361461)

Utilizator SimionCristiSimion Cristi Mihai SimionCristi Data 24 iulie 2026 15:15:51
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int timp[2001];
long long pretClient[2001];
long long castig[1501];
int main()
{
    int n;
    long long c;
    fin >> n >> c;
    for (int i = 1; i <= n; i++)
        fin >> timp[i] >> pretClient[i];
    long long profitMaxim = 0;
    for (int i = 1; i <= n; i++)
    {
        long long pret = pretClient[i];
        for (int t = 0; t <= 1500; t++)
            castig[t] = -c;
        for (int j = 1; j <= n; j++)
        {
            if (pretClient[j] >= pret)
                castig[timp[j]] = castig[timp[j]] + pret;
        }
        long long profitCurent = 0;
        for (int t = 0; t <= 1500; t++)
        {
            profitCurent = profitCurent + castig[t];
            if (profitCurent > profitMaxim)
                profitMaxim = profitCurent;
            if (profitCurent < 0)
                profitCurent = 0;
        }
    }
    fout << profitMaxim;
    return 0;
}