#include #include // Dost Velké Číslo™ #define dvc long long unsigned int #define index(x) ((index + x) % 5) int main () { // Stačí nám pamatovat si posledních pět // N - počet zatáček // cur - délka poslední roviny dvc N, cur, last [5]; // Abychom nemuseli pole posouvat, budeme se posouvat v poli int index = 0; // DVČ musíme číst pomocí %Lu scanf("%Lu", &N); for (dvc i = 0; i < N; i++) { scanf("%Lu", &cur); // Otestuje protnutí s před³poslední čarou // Nerovnosti se asi dají pochopit jen, pokud si je nakreslíte. // Testují, jestli konec čáry padnul do oblasti, ve které nutně // musel protnout jinou čáru. // ____ // | | // |___|__ // | // if (i > 2 && cur >= last[index(1)] && last[index(2)] >= last[index]) { printf("%Lu\n", i); return 0; } // Otestuje protnutí s před⁵poslední čarou // ________ // | | // |__|__ | // |___| // if (i > 4 && last[index(1)] >= last[index(3)] && cur >= last[index(1)] - last[index(3)] && last[index] <= last[index(2)] && last[index] >= last[index(2)] - last[index(4)]) { printf("%Lu\n", i); return 0; } // index + 4 === index - 1 (mod 5) index += 4; index %= 5; last[index] = cur; } // Sem se dostaneme, jen pokud jsme neprotli nikde nic printf("0\n"); return 0; }