Pagini recente » Monitorul de evaluare | Cod sursa (job #1296559) | Cod sursa (job #1287560) | Cod sursa (job #1263746) | Cod sursa (job #125537)
Cod sursa(job #125537)
#include <fstream.h>
ifstream fin("gardieni.in");
ofstream fout("gardieni.out");
struct sirul{
long a,b,c;
};
typedef struct sirul sip;
sip sir[50010];
long n,t,mat[100010];
long S;
void citire()
{
fin>>n>>t;
for (int i=0;i<n;i++)
fin>>sir[i].a>>sir[i].b>>sir[i].c;
fin.close();
}
void suma()
{
long min=0,poz=-1,nr=n;
while (1){
min=120000000;
poz=-1;
for (int j=0;j<n;j++)
{
if (sir[j].c<min)
{
min=sir[j].c;
poz=j;
}
}
if (poz!=-1)
{
for (int k=sir[poz].a ; k<=sir[poz].b ; k++)
if (mat[k]==0)
{
mat[k]=1;
S+=sir[poz].c;
nr--;
}
sir[poz].c=21434563;
}
if (nr==0)
break;
}
}
int main()
{
citire();
suma();
fout<<S<<"\n";
fout.close();
return 0;
}