#include <bits/stdc++.h> #define lld long long #define pii pair<int,int> #define mp make_pair #define s second #define f first #define pb push_back #ifdef WIN32 #define gcx getchar() #elif __linux__ #define gcx getchar_unlocked() #endif using namespace std; void scam(int *x) { int tt = 0; char z = '@'; while(z<'0' || z>'9')z=gcx; while((z>='0') && (z<='9')) tt = (tt<<3) + (tt<<1) + z - '0', z=gcx; *x = tt; } int dp[2048][2048]; int n,k,mn=1000000000; int t[2048][2048]; int main() { scam(&n); scam(&k); for(int i=0;i<n;++i){ for(int j=0;j<=i;++j){ scam(&t[i][j]); } } dp[0][0]=1; dp[1][0]=2; dp[1][1]=2; for(int i=2;i<n;++i) { dp[i][0]=i+1; for(int j=1;j<=i;++j){ dp[i][j]=1+dp[i-1][j-1]+dp[i-1][j]-dp[i-2][j-1]; } } for(int i=0;i<n;++i){ for(int j=0;j<=i;++j){ //printf("%d ",dp[i][j]); if(dp[i][j]<=k) mn=min(mn,t[i][j]); } //puts(""); } printf("%d",mn); 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 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 56 57 58 | #include <bits/stdc++.h> #define lld long long #define pii pair<int,int> #define mp make_pair #define s second #define f first #define pb push_back #ifdef WIN32 #define gcx getchar() #elif __linux__ #define gcx getchar_unlocked() #endif using namespace std; void scam(int *x) { int tt = 0; char z = '@'; while(z<'0' || z>'9')z=gcx; while((z>='0') && (z<='9')) tt = (tt<<3) + (tt<<1) + z - '0', z=gcx; *x = tt; } int dp[2048][2048]; int n,k,mn=1000000000; int t[2048][2048]; int main() { scam(&n); scam(&k); for(int i=0;i<n;++i){ for(int j=0;j<=i;++j){ scam(&t[i][j]); } } dp[0][0]=1; dp[1][0]=2; dp[1][1]=2; for(int i=2;i<n;++i) { dp[i][0]=i+1; for(int j=1;j<=i;++j){ dp[i][j]=1+dp[i-1][j-1]+dp[i-1][j]-dp[i-2][j-1]; } } for(int i=0;i<n;++i){ for(int j=0;j<=i;++j){ //printf("%d ",dp[i][j]); if(dp[i][j]<=k) mn=min(mn,t[i][j]); } //puts(""); } printf("%d",mn); return 0; } |