#include #include #define DIV_UP(i, divisor) ((i + divisor - 1) / divisor) int main(void) { int* heaps; int N; int max = 0; int total_count = 0; // 1. Načtení vstupu scanf("%d", &N); heaps = malloc(sizeof(int) * N); for (int i = 0; i < N; i++) { scanf("%d", &heaps[i]); if (heaps[i] > max) max = heaps[i]; total_count += heaps[i]; } // 2. Všechno odstraňování se děje až po všech přesunech a odstraňování // závisí na výšce nejvyššího sloupce → zkoušíme všechny možné výšky int total_time = max; for (int height = max; height > 0; height--) { int moves = 0; // Při přesouvání má smysl vytvářet vždy jen nové hromádky. // Ty ale již nemusíme počítat (jsou nižší než height), jde nám // jen o počet nutných přesunů. for (int i = 0; i < N; i++) if (heaps[i] > 0) moves += DIV_UP(heaps[i], height) - 1; if (height + moves < total_time) total_time = height + moves; } printf("%d\n", total_time); return 0; }