#include <cstdio> #include <utility> #include <algorithm> using namespace std; pair<int, int> tab[2005], tab2[2005]; int main() { int n, k, x, best; best = 5000; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { scanf("%d", &x); tab2[j].first = tab[j - 1].first + tab[j].second + 1; // piramida z (j - 1) + kolumna z j tab2[j].second = tab[j].second + 1; //tylko kolumna if (tab2[j].first <= k) best = min(best, x); } for (int j = 1; j <= i; j++) { tab[j] = make_pair(tab2[j].first, tab2[j].second); } } printf("%d\n", best); }
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 | #include <cstdio> #include <utility> #include <algorithm> using namespace std; pair<int, int> tab[2005], tab2[2005]; int main() { int n, k, x, best; best = 5000; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { scanf("%d", &x); tab2[j].first = tab[j - 1].first + tab[j].second + 1; // piramida z (j - 1) + kolumna z j tab2[j].second = tab[j].second + 1; //tylko kolumna if (tab2[j].first <= k) best = min(best, x); } for (int j = 1; j <= i; j++) { tab[j] = make_pair(tab2[j].first, tab2[j].second); } } printf("%d\n", best); } |