#include <bits/stdc++.h> using namespace std; const int N = 2e3; long long dp[N+7][N+7]; long long tab[N+7][N+7]; long long wyn; int n,k; int main() { cin>>n>>k; for(int i =0;i<n;i++) { for(int j =0;j<=i;j++) { cin>>tab[i+2][j+1]; if(i==0 and j==0) { wyn = tab[i+2][j+1]; } dp[i+2][j+1] = dp[i+1][j] + dp[i+1][j+1] - dp[i][j] + 1; if(dp[i+2][j+1]<=k and tab[i+2][j+1]<wyn) { wyn = tab[i+2][j+1]; } } } cout<<wyn; 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 27 28 29 30 | #include <bits/stdc++.h> using namespace std; const int N = 2e3; long long dp[N+7][N+7]; long long tab[N+7][N+7]; long long wyn; int n,k; int main() { cin>>n>>k; for(int i =0;i<n;i++) { for(int j =0;j<=i;j++) { cin>>tab[i+2][j+1]; if(i==0 and j==0) { wyn = tab[i+2][j+1]; } dp[i+2][j+1] = dp[i+1][j] + dp[i+1][j+1] - dp[i][j] + 1; if(dp[i+2][j+1]<=k and tab[i+2][j+1]<wyn) { wyn = tab[i+2][j+1]; } } } cout<<wyn; return 0; } |