Cod sursa(job #348149)

Utilizator miculprogramatorA Cosmina - vechi miculprogramator Data 14 septembrie 2009 16:37:41
Problema Reconst Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
using namespace std;

#define MAX 2000

long long N,M,x,y,z,i,a[MAX],s[MAX],j;

void preluc (long long x, long long y, long long z)
{
	if (!a[x])
	{
		a[x]=y;
		s[x]=z;
	}
	else if (a[x]<y) preluc (a[x]+1,y,z-s[x]);
		else if (a[x]>y) 
		{
			preluc (y+1,a[x],s[x]-z);
			a[x]=y;
			s[x]=z;
		}
}

int main()
{
	ifstream f("reconst.in");
	ofstream g("reconst.out");
	f>>N>>M;
	for (i=1;i<=M;++i)
	{
		f>>x>>y>>z;
		preluc (x,y,z);
	}
	f.close();
	for (i=N;i;--i)
		for (j=i+1;j<=a[i];++j)
			s[i]-=s[j];
	for (i=1;i<=N;++i)
		g<<s[i]<<" ";
	g<<'\n';
	g.close();
	return 0;
}