Cod sursa(job #1946309)

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

constexpr int maxn = 1e6 + 100;

list<int> adauga[maxn], scoate[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].push_back(cost),
        scoate[dr+1].push_back(cost);
    long long rez = 0;
    multiset<int> candidates;
    for(int i = 1; i <= t; ++i){
        for(const auto x : scoate[i]) candidates.erase(candidates.find(x));
        for(const auto x : adauga[i]) candidates.insert(x);
        rez += *begin(candidates); }
    g << rez << endl; }