Cod sursa(job #937435)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 10 aprilie 2013 12:26:35
Problema Reconst Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>

using namespace std;

ifstream fin("reconst.in"); ofstream fout("reconst.out");


int a[3000], s[3000], n, m, x, y, z;

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()
{

    fin >> n >> m;

    for(int i = 1; i <= m; ++i)
    {
        fin >> x >> y >> z;
        Update(x,y,z);
    }

    for (int i = n; i >= 0; --i)
        for (int j = i + 1; j <= a[i]; ++j)
            s[i] -= s[j];

    for (int i = 1; i <= n; ++i)
        fout << s[i] << " ";

    fin.close(); fout.close();
    return 0;
}