#include <bits/stdc++.h> using namespace std; int n, k, bottle; int best; int triangle(int x) { return (x * (x+1))/2; } int min_to_remove(int l, int m) { int max_to_stay = triangle(n - l + m - 1) + triangle(n - m - 1) - triangle(n - l - 2); return triangle(n) - max_to_stay; } int main() { scanf("%d%d", &n, &k); best = 1000000; for(int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { scanf("%d", &bottle); if ((min_to_remove(i, j) <= k) && (best > bottle)) { best = bottle; } } } printf("%d\n", best); }
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 | #include <bits/stdc++.h> using namespace std; int n, k, bottle; int best; int triangle(int x) { return (x * (x+1))/2; } int min_to_remove(int l, int m) { int max_to_stay = triangle(n - l + m - 1) + triangle(n - m - 1) - triangle(n - l - 2); return triangle(n) - max_to_stay; } int main() { scanf("%d%d", &n, &k); best = 1000000; for(int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { scanf("%d", &bottle); if ((min_to_remove(i, j) <= k) && (best > bottle)) { best = bottle; } } } printf("%d\n", best); } |