#include <cstdio> #include <algorithm> static unsigned mem[2048][2048]; unsigned steps_for(unsigned level, unsigned order) { if (order == 1) { return level; } mem[level][order] = mem[level - 1][order - 1] + level - order + 1; //printf("mem[%u][%u] = %u; + %u\n", level - 1, order - 1, mem[level-1][order-1], level - order + 1); return mem[level][order]; } int main(int argc, char* argv[]) { for (unsigned level = 1; level < 2048; ++level) { mem[level][1] = level; } unsigned levels, max_step, value, best_wine = std::numeric_limits<unsigned>::max(); scanf("%u %u\n", &levels, &max_step); for (unsigned level = 1; level <= levels; ++level) { for (unsigned order = 1; order <= level; ++order) { scanf("%u", &value); unsigned normalized_order = std::min(order, level - order + 1); unsigned steps = steps_for(level, normalized_order); //printf("Steps for %u: %u\n", value, steps); if (steps <= max_step) { best_wine = std::min(best_wine, value); } } } printf("%u", best_wine); }
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 | #include <cstdio> #include <algorithm> static unsigned mem[2048][2048]; unsigned steps_for(unsigned level, unsigned order) { if (order == 1) { return level; } mem[level][order] = mem[level - 1][order - 1] + level - order + 1; //printf("mem[%u][%u] = %u; + %u\n", level - 1, order - 1, mem[level-1][order-1], level - order + 1); return mem[level][order]; } int main(int argc, char* argv[]) { for (unsigned level = 1; level < 2048; ++level) { mem[level][1] = level; } unsigned levels, max_step, value, best_wine = std::numeric_limits<unsigned>::max(); scanf("%u %u\n", &levels, &max_step); for (unsigned level = 1; level <= levels; ++level) { for (unsigned order = 1; order <= level; ++order) { scanf("%u", &value); unsigned normalized_order = std::min(order, level - order + 1); unsigned steps = steps_for(level, normalized_order); //printf("Steps for %u: %u\n", value, steps); if (steps <= max_step) { best_wine = std::min(best_wine, value); } } } printf("%u", best_wine); } |