#include <bits/stdc++.h> using namespace std; int n, k, a, mini, val; int tab[3000]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); mini = 10000; cin >> n >> k; tab[1] = 0; for(int i = 1; i <= n; ++ i){ tab[i + 1] = 0; for(int j = 1; j <= i; ++ j){ val = tab[j] + j; tab[j] = tab[j] + j; cin >> a; if(val <= k && a < mini) mini = a; } } cout << mini; return 0; }
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 | #include <bits/stdc++.h> using namespace std; int n, k, a, mini, val; int tab[3000]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); mini = 10000; cin >> n >> k; tab[1] = 0; for(int i = 1; i <= n; ++ i){ tab[i + 1] = 0; for(int j = 1; j <= i; ++ j){ val = tab[j] + j; tab[j] = tab[j] + j; cin >> a; if(val <= k && a < mini) mini = a; } } cout << mini; return 0; } |