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 | #include <bits/stdc++.h>
using namespace std;
void solve()
{
int N, K;
cin >> N >> K;
int best = numeric_limits<int>::max();
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= i; j++)
{
int V;
cin >> V;
int R = (i * (i + 1)) / 2 - ((j - 1) * j) / 2 - ((i - j) * (i - j + 1)) / 2;
if(R <= K)
best = min(best, V);
}
}
cout << best << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
|