Cod sursa(job #485884)

Utilizator borsoszalanBorsos Zalan borsoszalan Data 19 septembrie 2010 20:01:00
Problema Reconst Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <stdio.h>
long n,m,i,j,x,y,z;
long a[2048],s[2048];

void update(int x, int y, int z){
     if (!a[x]){
        a[x]=y;s[x]=z;
     }else
        if (a[x]<y)
           update (a[x]+1,y,z-s[x]);
        else if (a[x]>y){ update (y+1,a[x],s[x]-z); a[x]=y; s[x]=z; }
}
int main(){
    freopen("reconst.in","r",stdin);
    freopen("reconst.out","w",stdout);
    scanf("%ld %ld",&n,&m);
    for (i=1;i<=m;++i){
        scanf("%ld %ld %ld",&x,&y,&z);
        update(x,y,z);
    }
    for (i=n;i;--i)
        for (j=i+1;j<=a[i];++j)
            s[i]-=s[j];
    for (i=1;i<=n;++i)printf("%ld ",s[i]);
printf("\n");
return 0;
}