Cod sursa(job #2328551)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 25 ianuarie 2019 21:47:38
Problema Gardieni Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

struct oferta
{
    int a, b, c;
} v[50005];

inline bool cmp(oferta x, oferta y)
{
    return x.c < y.c;
}

bool used[1000005];

int main()
{
    int n, t;
    fin >> n >> t;

    for(int i = 1; i <= n; ++i)
        fin >> v[i].a >> v[i].b >> v[i].c;

    sort(v + 1, v + n + 1, cmp);

    long long cnt = 0, i = 1, cost = 0;
    while(cnt <= t)
    {
        for(int j = v[i].a; j <= v[i].b; ++j)
            if(!used[j])
            {
                used[j] = 1;
                ++cnt;
                cost += v[i].c;
            }
        ++i;
    }

    fout << cost << '\n';
    return 0;
}