#include <cstdio> #include <iostream> #include <string> #include <vector> #include <stdlib.h> #include <time.h> #include <algorithm> #include <cmath> #include <fstream> #include <utility> using namespace std; int b[2010][2010], r[2030]; int main() { int n, h, k, w; scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { for (int j = i; j > 0; j--) { scanf("%d", &h); b[j][i - j + 1] = b[j - 1][i - j + 1] + b[j][i - j] - b[j - 1][i - j] + 1; if (r[h] == 0) r[h] = b[j][i - j + 1]; else r[h] = min(r[h], b[j][i - j + 1]); } } for (int i = 2019; i > 0; i--) { if (r[i] != 0) { if (r[i] <= k) w = i; } } printf("%d", w); //system("pause"); } //5, 38, 54
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 | #include <cstdio> #include <iostream> #include <string> #include <vector> #include <stdlib.h> #include <time.h> #include <algorithm> #include <cmath> #include <fstream> #include <utility> using namespace std; int b[2010][2010], r[2030]; int main() { int n, h, k, w; scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { for (int j = i; j > 0; j--) { scanf("%d", &h); b[j][i - j + 1] = b[j - 1][i - j + 1] + b[j][i - j] - b[j - 1][i - j] + 1; if (r[h] == 0) r[h] = b[j][i - j + 1]; else r[h] = min(r[h], b[j][i - j + 1]); } } for (int i = 2019; i > 0; i--) { if (r[i] != 0) { if (r[i] <= k) w = i; } } printf("%d", w); //system("pause"); } //5, 38, 54 |