Pagini recente » Cod sursa (job #2834408) | Cod sursa (job #1732910) | Cod sursa (job #2535436) | Cod sursa (job #1086234) | Cod sursa (job #208553)
Cod sursa(job #208553)
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
struct nod {
int a, b, s;
nod(){};
nod(int _a, int _b, int _c) {a = _a; b = _b; s = _c;}
};
int N, M;
int puse = 0;
int v[2888];
vector<nod> V;
#define ALL(a) a.begin(), a.end()
bool operator<(const nod &a, const nod &b) {
if (a.a < b.a) return true;
if (a.a > b.a) return false;
if (a.b < b.b) return true;
return false;
}
int main() {
freopen("reconst.in", "r", stdin);
freopen("reconst.out", "w", stdout);
scanf("%d %d", &N, &M);
while (M--) {
int a, b, s;
scanf("%d %d %d", &a, &b, &s);
V.push_back(nod(a, b, s));
}
sort(ALL(V));
for (int i = 0; i < V.size(); ++i)
for (int j = i + 1; j < V.size(); ++j) {
// if (V[i].a == V[j].a) {V[j].a = V[i].b + 1; V[j].s -= V[i].s; continue;}
if (V[i].b == V[j].b) {V[i].b = V[j].a - 1; V[i].s -= V[j].s;}
}
sort(ALL(V));
for (int i = 0; i < V.size(); ++i) {
int sum = V[i].s;
// printf("%d %d %d\n", V[i].a, V[i].b, V[i].s);
int a = V[i].a, b = V[i].b;
while (a <= b && a <= puse) {sum -= v[a];++a;}
if (a <= b) v[a] = sum;
puse = max(puse, b);
}
for (int i = 1; i <= N; ++i) if (i == 1) printf("%d", v[i]); else printf(" %d", v[i]);
printf("\n");
return 0;
}