Pagini recente » Cod sursa (job #2219891) | Cod sursa (job #304191) | Cod sursa (job #3170598) | Cod sursa (job #863785) | Cod sursa (job #937435)
Cod sursa(job #937435)
#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;
}