#include <iostream> #include <limits.h> #include <string.h> #include <queue> #include <iomanip> #include <cmath> #include <set> #include <map> #include <vector> #include <algorithm> #include <iomanip> #include <unordered_map> using namespace std; typedef long long LL; const int MOD = 1e9+7; int t[2007][2007]; int res = 3000; int solve(int i, int j) { int left = max(j - 2, 0); int right = max((i - j + 1 - 2), 0); i --; //cout << i << " " << j << " " << left << " " << right << " " << << "\n"; return ((i * (i + 1)) / 2) - (left * (left + 1) / 2) - (right * (right + 1) / 2) + 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); LL n, k; cin >> n >> k; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= i; j ++) { cin >> t[i][j]; if(solve(i, j) <= k) res = min(res, t[i][j]); } } cout << res << "\n"; 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 | #include <iostream> #include <limits.h> #include <string.h> #include <queue> #include <iomanip> #include <cmath> #include <set> #include <map> #include <vector> #include <algorithm> #include <iomanip> #include <unordered_map> using namespace std; typedef long long LL; const int MOD = 1e9+7; int t[2007][2007]; int res = 3000; int solve(int i, int j) { int left = max(j - 2, 0); int right = max((i - j + 1 - 2), 0); i --; //cout << i << " " << j << " " << left << " " << right << " " << << "\n"; return ((i * (i + 1)) / 2) - (left * (left + 1) / 2) - (right * (right + 1) / 2) + 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); LL n, k; cin >> n >> k; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= i; j ++) { cin >> t[i][j]; if(solve(i, j) <= k) res = min(res, t[i][j]); } } cout << res << "\n"; return 0; } |