Cod sursa(job #1780495)

Utilizator silkMarin Dragos silk Data 16 octombrie 2016 12:08:58
Problema Gardieni Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>
#define NMax 1000000
#define DIM 10000
#define INF 1<<30
char buff[DIM];
int poz;

int cost[NMax+1];

void citeste(int& numar)
{
    numar = 0;
    while(buff[poz]<'0'||buff[poz]>'9')
    if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;

    while(buff[poz]>='0'&&buff[poz]<='9')
    {
        numar = numar*10 + buff[poz] - '0';
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
    }
}

int main(){
    freopen("gardieni.in","r",stdin);
    freopen("gardieni.out","w",stdout);

    int i,j,N,T,x,y,z;
    long long ans = 0;

    scanf("%d %d",&N,&T);
    for(i = 1; i <= T; ++i) cost[i] = INF;
    for(i = 1; i <= N; ++i)
    {
        citeste(x);
        citeste(y);
        citeste(z);
        for(j = x; j <= y; ++j)
        if( cost[j] > z ) cost[j] = z;
    }

    for(i = 1; i <= T; ++i) ans = ans + cost[i];
    printf("%lld\n",ans);



return 0;
}