#include <iostream> #include <array> using namespace std; int main(){ int n, k; cin >> n >> k; int wine[n * (n + 1) / 2]; for(int i = 0; i < n * (n + 1) / 2; i++) cin >> wine[i]; int minn = wine[0]; for(int i = 0; i < n; i++) for(int j = 1; j < i + 2; j++){ int a = 0; for(int i2 = 0; i2 < min(j, i - j + 2); i2++) a += i + 1 - i2; if(a <= k && wine [i * (i + 1) / 2 + j - 1] < minn) minn = wine [i * (i + 1) / 2 + j - 1]; } cout << minn; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> #include <array> using namespace std; int main(){ int n, k; cin >> n >> k; int wine[n * (n + 1) / 2]; for(int i = 0; i < n * (n + 1) / 2; i++) cin >> wine[i]; int minn = wine[0]; for(int i = 0; i < n; i++) for(int j = 1; j < i + 2; j++){ int a = 0; for(int i2 = 0; i2 < min(j, i - j + 2); i2++) a += i + 1 - i2; if(a <= k && wine [i * (i + 1) / 2 + j - 1] < minn) minn = wine [i * (i + 1) / 2 + j - 1]; } cout << minn; } |