Pagini recente » Cod sursa (job #452930) | Cod sursa (job #527450) | Cod sursa (job #2718060) | Cod sursa (job #1323172) | Cod sursa (job #2328551)
#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;
}