Pagini recente » Cod sursa (job #34553) | Cod sursa (job #239636) | Cod sursa (job #1236871) | Cod sursa (job #2458780) | Cod sursa (job #1946310)
#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; }