Cod sursa(job #1646615)

Utilizator theodor.moroianuTheodor Moroianu theodor.moroianu Data 10 martie 2016 16:54:18
Problema Carnati Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <set>
#include <vector>
using namespace std;

vector<int> v[2000];

int main()
{
    set<int> pret;
    fstream in("carnati.in");
    int n, c, t, p;
    in >> n >> c;
    while (n--) {
        in >> t >> p;
        pret.insert(p);
        v[t].push_back(p);
    }
    int best = 0;
    int act;
    for (auto cost : pret) {
        act = 0;
        for (int i = 0; i <= 1600; i++) {
            if (act > best) {
                best = act;
            }
            act -= c;
            for (auto j : v[i]) {
                if (j >= cost) {
                    act += cost;
                }
            }
            if (act < 0)
                act = 0;
        }
    }
    ofstream out("carnati.out");
    out << best;
    return 0;
}