#include <stdio.h> #include <string.h> int main() { int n, k, y, bestY=1000*1000; scanf("%d %d", &n, &k); // printf("n = %d; k = %d\n", n, k); for (int row = 1; row <= n; row++) { // printf("row = %d; cols: ", row); for (int col = 1; col <= row; col++) { scanf("%d", &y); int distToEdge = (col < row - col + 1 ? col : row - col + 1); int toRemove = (row - distToEdge + 1) * distToEdge; // printf("col = %d (y=%d, toRemove=%d), ", col, y, toRemove); if (toRemove <= k) { bestY = (bestY < y ? bestY : y); } } // printf("\n"); } printf("%d", bestY); 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 | #include <stdio.h> #include <string.h> int main() { int n, k, y, bestY=1000*1000; scanf("%d %d", &n, &k); // printf("n = %d; k = %d\n", n, k); for (int row = 1; row <= n; row++) { // printf("row = %d; cols: ", row); for (int col = 1; col <= row; col++) { scanf("%d", &y); int distToEdge = (col < row - col + 1 ? col : row - col + 1); int toRemove = (row - distToEdge + 1) * distToEdge; // printf("col = %d (y=%d, toRemove=%d), ", col, y, toRemove); if (toRemove <= k) { bestY = (bestY < y ? bestY : y); } } // printf("\n"); } printf("%d", bestY); return 0; } |