#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define ST first #define ND second #define PB push_back const int maxn = 2100; int tot[maxn][maxn]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; int res=10000; for(int i=1; i <= n; i++) { for(int j=1; j <= i; j++) { int a; cin >> a; tot[i][j] = tot[i-1][j-1]+tot[i-1][j]+1; if(i > 1) { tot[i][j]-=tot[i-2][j-1]; } // cout << tot[i][j] << " "; if(tot[i][j] <= k) { res = min(res, a); } } // cout << "\n"; } cout << res << "\n"; }
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define ST first #define ND second #define PB push_back const int maxn = 2100; int tot[maxn][maxn]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; int res=10000; for(int i=1; i <= n; i++) { for(int j=1; j <= i; j++) { int a; cin >> a; tot[i][j] = tot[i-1][j-1]+tot[i-1][j]+1; if(i > 1) { tot[i][j]-=tot[i-2][j-1]; } // cout << tot[i][j] << " "; if(tot[i][j] <= k) { res = min(res, a); } } // cout << "\n"; } cout << res << "\n"; } |