#include #include #include #include #include #include using namespace std; #define TRACE(x) cerr << #x << " = " << x << endl #define REP(i, n) for (int i=0; i P; #define X first #define Y second const int MAX = 1<<17; ll gauss(int x) { return (ll) x * (x + 1) / 2; } ll povrh2(int x) { return (ll) x * (x - 1) / 2; } int tree, bck, fwd, crss; int n; int vel; int v1; int v2; int vecih; int manjih; int gor, dol; vector V[MAX]; void add(int a, int b) { // printf("ADD %d %d\n", a, b); V[a].push_back(b); } void ajmo(int kol) { int poz = 2; int treba_bck = bck; int treba_fwd = fwd; int treba_crss = crss; vector > Gr; ll gd = n - 1, preko = 0; for (int i=0; i= manjih) t_vel = v2; vector T{1, poz}; add(1, poz); poz++; for (int j=0; j= crss && gd >= bck + fwd + tree && gd / 2 - tree >= fwd) { TRACE(i); TRACE(gd); TRACE(preko); ajmo(i); return 0; } } for (int i=1; i<=n; i++) { gor = i; dol = n - i; ll preko = povrh2(dol); ll gd = 2 * (ll) gor * dol; gd += 2 * povrh2(gor); if (preko >= crss && gd >= bck + fwd + tree && gd / 2 - tree >= fwd) { ajmo2(); return 0; } } printf("-1\n"); return 0; }