Pagini recente » Cod sursa (job #1050676) | Cod sursa (job #1448368) | Cod sursa (job #140262) | Cod sursa (job #1249019) | Cod sursa (job #208558)
Cod sursa(job #208558)
#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));
while (1) { int ok = 0;
for (int i = 0; i < V.size(); ++i)
for (int j = 0; j < V.size(); ++j) if (i!=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;ok=1;}
}
if (ok == 0) break;
}
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;
}