#include <cstdio> #include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <set> #include <map> using namespace std; int k, n; int age[2004][2004], height[2004][2004]; int main(){ for(int i=0; i<2004; i++){ for(int j=0; j<2004; j++){ age[i][j]=0; height[i][j]=0; } } scanf("%d %d", &n, &k); int max_age=55555; for(int i=1; i<=n; i++){ for(int j=1; j<=i; j++){ scanf("%d", &age[i][j]); height[i][j]=height[i-1][j-1] + height[i-1][j] + 1 - ((i>1)?height[i-2][j-1]:0); if(height[i][j]<=k && age[i][j]<max_age) max_age=age[i][j]; } } printf("%d\n", max_age); 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 | #include <cstdio> #include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <set> #include <map> using namespace std; int k, n; int age[2004][2004], height[2004][2004]; int main(){ for(int i=0; i<2004; i++){ for(int j=0; j<2004; j++){ age[i][j]=0; height[i][j]=0; } } scanf("%d %d", &n, &k); int max_age=55555; for(int i=1; i<=n; i++){ for(int j=1; j<=i; j++){ scanf("%d", &age[i][j]); height[i][j]=height[i-1][j-1] + height[i-1][j] + 1 - ((i>1)?height[i-2][j-1]:0); if(height[i][j]<=k && age[i][j]<max_age) max_age=age[i][j]; } } printf("%d\n", max_age); return 0; } |