/* Notice: - This account submits solutions that result from the collaboration of two (non-Polish) individuals. - We acknowledge that our participation is completely unofficial. - We just want to be able to submit our solutions until the end of the week. Thank you :)! */ #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int kMaxN = 2100; int cnt[kMaxN][kMaxN]; void Reset() { memset(cnt, 0, sizeof(cnt)); } bool Solve() { Reset(); int n, k; if(scanf("%d %d", &n, &k) < 2) return false; cnt[1][1] = 1; int ans = 3010; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) { int age; scanf("%d", &age); if (i == 1) { cnt[i][j] = 1; } else { cnt[i][j] = cnt[i - 1][j - 1] + cnt[i - 1][j] - cnt[i - 2][j - 1] + 1; } if (cnt[i][j] <= k) { ans = min(ans, age); } } } cout << ans << "\n"; return true; } int main() { while(Solve()); }
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | /* Notice: - This account submits solutions that result from the collaboration of two (non-Polish) individuals. - We acknowledge that our participation is completely unofficial. - We just want to be able to submit our solutions until the end of the week. Thank you :)! */ #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int kMaxN = 2100; int cnt[kMaxN][kMaxN]; void Reset() { memset(cnt, 0, sizeof(cnt)); } bool Solve() { Reset(); int n, k; if(scanf("%d %d", &n, &k) < 2) return false; cnt[1][1] = 1; int ans = 3010; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) { int age; scanf("%d", &age); if (i == 1) { cnt[i][j] = 1; } else { cnt[i][j] = cnt[i - 1][j - 1] + cnt[i - 1][j] - cnt[i - 2][j - 1] + 1; } if (cnt[i][j] <= k) { ans = min(ans, age); } } } cout << ans << "\n"; return true; } int main() { while(Solve()); } |