Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- #include <ctime>
- bool sh = 1;
- int N, n;
- vector <int> gen() {
- srand(time(0));
- n = rand() % 5 + 2;
- vector <int> a;
- for (int i = 0; i < n; ++i) {
- int x = rand() % 10 + 1;
- a.pb(x);
- N += x;
- }
- sort(a.begin(), a.end());
- reverse(a.begin(), a.end());
- //cv(a);
- return a;
- }
- bool ok(vector <int> a) {
- for (int i = 0; i < a.size() - 1; ++i) {
- if (a[i] == a[i + 1]) {
- return 0;
- }
- }
- return 1;
- }
- vector <int> my(vector <int> a) {
- int dif = a[0] - a[1] - 1;
- a[0] -= dif;
- vector <int> ans(N);
- int id = -1, cnt = 0;
- int to = n;
- if (sh) {
- cout << "A\n";
- }
- int nxt = n;
- while (cnt < N) {
- to = nxt;
- int j = -1;
- if (sh) {
- cout << "B\n";
- cout << "to = " << to << "\n";
- cout << "cnt = " << cnt << "\n";
- }
- while (j + 1 < to) {
- id++;
- if (sh) cout << "id j = " << id << ' ' << j << "\n";
- if (sh) {
- cout << "a\n";
- cv(a);
- cout << "dif = " << dif << "\n";
- }
- if (j == -1 && dif > 0) {
- if (sh) {
- cout << "C\n";
- }
- ans[id] = 0;
- j = 0;
- a[0]--;
- cnt++;
- continue;
- }
- if (dif > 0) {
- if (sh) {
- //cout << "del dif\n";
- cout << "D\n";
- }
- if (id == 0 || id > 0 && ans[id - 1] != 0) {
- ans[id] = 0;
- dif--;
- cnt++;
- continue;
- }
- }
- j++;
- a[j]--;
- cnt++;
- if (sh) {
- cout << "E\n";
- cout << "j = " << j << "\n";
- }
- if (sh) {
- //cout << "just go\n";
- }
- ans[id] = j;
- if (a[j] == 0) {
- nxt = min(nxt, j);
- }
- }
- }
- if (ok(ans)) {
- return ans;
- }
- return {-1};
- }
- bool random = 1;
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- vector <int> a;
- if (sh && random) {
- a = gen();
- } else if (sh) {
- cin >> n;
- a.resize(n);
- for (int &i: a) {
- cin >> i;
- N += i;
- }
- sort(a.begin(), a.end());
- reverse(a.begin(), a.end());
- }
- if (sh) {
- cout << "N = " << N <<"\n";
- cout << "a\n";
- cv(a);
- }
- vector <int> r = my(a);
- if (sh) {
- cout << "r\n";
- cv(r);
- }
- }
- /*
- N = 58
- a
- 5
- 18 17 11 8 4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement