Cod sursa(job #849132)

Utilizator prettythingBereschi Paul prettything Data 6 ianuarie 2013 15:38:25
Problema Reconst Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
using namespace std;
int n,m,i,j,x,y,z;
int a[2050],s[2050];
  
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(){
    ifstream fin("reconst.in");
    ofstream fout("reconst.out");
    fin>>n>>m;
    for (i=1;i<=m; ++i){
        fin>>x>>y>>z;
        update(x,y,z);
    }
    for (i=n; i>0; --i)
        for (j=i+1; j<=a[i]; ++j) s[i]-=s[j];
    for (i=1;i<=n;++i) fout<<s[i]<<" ";
  return 0;
}