1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<iostream>
#include<algorithm>

using namespace std;

#ifdef KICIA
#define MAGIA(x) x
#else
#define MAGIA(x)
#endif // KICIA

struct Miasto{
    int moc_bazowa; //dla fabryk zaczynamy od minusa i idziemy do 0, dla elektrowni idziemy od plusa i idziemy do 0
    int moc_act;
    int punkt;
    bool is_factory;
};

Miasto tab_city[500001];

int main(){
    ios_base::sync_with_stdio(false);
    int n, sum_fab = 0, sum_ele = 0, tmp, it_c = 0, moc=0, sum_r = 0, sum_l = 0, mini = 1000000001;
    cin>>n;
    for(int i=0; i<n; ++i){
        cin>>tmp;
        if(tmp > 0){
            sum_ele += tmp;
            tab_city[it_c].moc_bazowa = tmp;
            tab_city[it_c].moc_act = tmp;
            tab_city[it_c].punkt = (i+1);
            tab_city[it_c].is_factory = false;
            it_c++;
        }
        if(tmp < 0){
            sum_fab += tmp;
            tab_city[it_c].moc_bazowa = tmp;
            tab_city[it_c].moc_act = 0;
            tab_city[it_c].punkt = (i+1);
            tab_city[it_c].is_factory = true;
            it_c++;
        }
    }
    if(sum_ele < (sum_fab * (-1))){
        cout<<"-1";
        return 0;
    }
    MAGIA(
        for (int i=0; i<it_c; ++i){
            cout<<i<<" "<<tab_city[i].moc_bazowa<<" "<<tab_city[i].moc_act<<" "<<tab_city[i].punkt<<" "<<tab_city[i].is_factory<<endl;
        }
          )

    /*for(int i=0; i<factory.size(); ++i){
        for(int j = 0; j<ele.size(); ++j){
            moc += tab_city[ele[j]].moc_act;
            if(tab_city[ele[j]].moc_act < mini){
                mini = tab_city[ele[j]].moc_act;
            }
            if(tab_city[ele[j]].punkt > tab_city[factory[i]].punkt){
                temp_ele.push_back(ele[j], 'r');
            }else{
                temp_ele.push_back(ele[j], 'l');
            }
            if((tab_city[factory[i]].moc_bazowa + moc) >= 0){
                if((tab_city[factory[i]].moc_bazowa + moc - mini) >= 0){

                }else{

                }
                mini = 1000000001;
                break;
            }
        }
    }*/



    return 0;
}