Cod sursa(job #2650153)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 17 septembrie 2020 16:17:07
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("carnati.in");
ofstream out("carnati.out");

vector<int> times[1505];
int c;

int test(int price)
{
    int max_here = 0, max_max = 0;
    for(int i = 0; i < 1505; i++)
    {
        max_here -= c;
        for(auto customer : times[i])
        {
            if(customer >= price) {
                max_here += price;
            }
        }

        max_max = max(max_max, max_here);
        max_here = max(max_here, 0);
    }

    return max_max;
}

int main()
{

    int n; in >> n >> c;

    for(int i = 0; i < n; ++i)
    {
        int t, cc; in >> t >> cc;
        times[t].push_back(cc);
    }

    int maxim = -1;
    for(int i = 0; i < 1505; i++)
    {
        for(auto prc : times[i]) {
            maxim = max(maxim, test(prc));

            int num = test(prc);
            //cout << prc << " " << num << endl;
        }
    }

    out << maxim;

    return 0;
}