Cod sursa(job #1946310)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 30 martie 2017 06:59:21
Problema Gardieni Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 1e6 + 100;

struct nod{ int val; nod *next; };

nod *scoate[maxn] = {}, *adauga[maxn] = {};
int n, t;

ifstream f("gardieni.in");
ofstream g("gardieni.out");

int main(){
    f >> n >> t;
    for(int i = 0, st, dr, cost; i < n; ++i)
        f >> st >> dr >> cost,
        adauga[st] = new nod { cost, adauga[st] },
        scoate[dr+1] = new nod { cost, scoate[dr+1] };
    long long rez = 0;
    multiset<int> candidates;
    for(int i = 1; i <= t; ++i){
        for(nod *x = scoate[i]; x; x = x->next)
            candidates.erase(candidates.find(x->val));
        for(nod *x = adauga[i]; x; x = x->next)
            candidates.insert(x->val);
        rez += *begin(candidates); }
    g << rez << endl; }