#include <bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; typedef unsigned long ul; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; vector<vector<long long>> wina(n, vector<long long>(n, 0)); long long res = 2019; for(long long i = 0; i < n; ++i) { for(ll j = 0; j<=i; ++j) { ll rocznik; cin >> rocznik; wina[i][j] = 1; if(i-1 >=0) { if(j-1 >= 0) { wina[i][j] += wina[i-1][j-1]; } wina[i][j] += wina[i-1][j]; if(i-2 >=0 && j-1 >= 0) { wina[i][j] -= wina[i-2][j-1]; } if(wina[i][j] <= k && rocznik < res) res = rocznik; } //cout << wina[i][j] << " "; } //cout << endl; } cout << res << endl; }
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 | #include <bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; typedef unsigned long ul; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; vector<vector<long long>> wina(n, vector<long long>(n, 0)); long long res = 2019; for(long long i = 0; i < n; ++i) { for(ll j = 0; j<=i; ++j) { ll rocznik; cin >> rocznik; wina[i][j] = 1; if(i-1 >=0) { if(j-1 >= 0) { wina[i][j] += wina[i-1][j-1]; } wina[i][j] += wina[i-1][j]; if(i-2 >=0 && j-1 >= 0) { wina[i][j] -= wina[i-2][j-1]; } if(wina[i][j] <= k && rocznik < res) res = rocznik; } //cout << wina[i][j] << " "; } //cout << endl; } cout << res << endl; } |