Cod sursa(job #208558)

Utilizator vlad_DVlad Dumitriu vlad_D Data 17 septembrie 2008 10:21:53
Problema Reconst Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#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;
    }