#include <iostream> using namespace std; const int BIGG = 5000000; const int MAX_YEAR = 10000; int depths[BIGG]; int main() { int n, k; cin >> n; cin >> k; int array_it = 0; int min_val = MAX_YEAR; for(int level=1; level<=n; level++) { for(int i=0; i<level; i++) { int value = MAX_YEAR; cin >> value; int right_up_it = array_it - level + 1; int depth = i + 1; if (right_up_it >= 0 && right_up_it < array_it - i) { depth += depths[right_up_it]; } if (depth <= k && value < min_val) { min_val = value; } depths[array_it] = depth; array_it++; } } cout << min_val << endl; }
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 | #include <iostream> using namespace std; const int BIGG = 5000000; const int MAX_YEAR = 10000; int depths[BIGG]; int main() { int n, k; cin >> n; cin >> k; int array_it = 0; int min_val = MAX_YEAR; for(int level=1; level<=n; level++) { for(int i=0; i<level; i++) { int value = MAX_YEAR; cin >> value; int right_up_it = array_it - level + 1; int depth = i + 1; if (right_up_it >= 0 && right_up_it < array_it - i) { depth += depths[right_up_it]; } if (depth <= k && value < min_val) { min_val = value; } depths[array_it] = depth; array_it++; } } cout << min_val << endl; } |