Pagini recente » Cod sursa (job #1082494) | Cod sursa (job #626916) | Cod sursa (job #2785886) | Cod sursa (job #3125577) | Cod sursa (job #475899)
Cod sursa(job #475899)
#include<stdio.h>
#include<stdlib.h>
#define tmax 1000100
#define nmax 50020
#define inf 1
int i,n,t;
struct asd{int a; int b;long long c;};
asd tomb[nmax];
int ido[tmax];
int cmp(const void *a, const void *b)
{return (((asd*)a)->c>((asd*)b)->c);}
int main()
{
freopen("gardieni.in", "r", stdin);
freopen("gardieni.out", "w", stdout);
scanf("%d %d", &n, &t);
for(i=1;i<=n;i++)
scanf("%d%d%lld", &tomb[i].a, &tomb[i].b, &tomb[i].c);
tomb[0].c=-inf;
qsort(tomb, n+1, sizeof(asd), cmp);
long long f=0;
for(i=1;i<=n;i++)
{
int x;
for(x=tomb[i].a;x<=tomb[i].b;x++)
if(ido[x]==0)
{
ido[x]=1;
f+=tomb[i].c;
}
}
printf("%lld", f);
return 0;
}