#ifndef LOCAL #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> using namespace std; // to jest debug() << imie(a) << imie(b) << imie((char)c); #define R22(r) template <class c> typename enable_if<sizeof(dud<c>(0)) r,muu&>::type operator<<(c g) template <class c> struct rge {c b, e;}; template <class c> rge<c> range(c i, c j) {return rge<c>{i, j};} template <class c> auto dud(c*r)->decltype(cerr << *r); template <class c> char dud(...); struct muu { #ifdef LOCAL stringstream a; ~muu() {cerr << a.str() << endl;} R22(>=2) {a << boolalpha << g; return *this;} R22(==1) {return *this << range(begin(g), end(g));} template <class c > muu & operator<<( rge<c> u) { a << "["; for (c i = u.b; i != u.e; ++i) *this << ", " + 2 * (i == u.b) << *i; return *this << "]"; } template <class c, class m > muu & operator<<( pair <m,c> r) {return *this << "(" << r.first << ", " << r.second << ")";} #else template <class c > muu & operator<<( const c&){return *this;} #endif muu & operator()(){return *this;} }; #define imie(r) "[" #r ": " << (r) << "] " #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ") // to jest dodawanie par, mozna ominac template<typename T, typename S> pair<T, S> operator+(pair<T,S> a, pair<T,S>b) {return {a.first+b.first, a.second+b.second};} template<typename T> T& mini(T& a, T b) { return b < a ? a=b : a; } template<typename T> T& maxi(T& a, T b) { return b > a ? a=b : a; } using ll = long long; using ull = unsigned long long; using ld = long double; using pld = pair<ld, ld>; using pii = pair<int, int>; const int MAXN = 2001; int t[MAXN][MAXN]; int main() { int n,k; scanf("%d%d", &n, &k); int w = 1e9; for (int y = 1; y <= n; y++) { for (int x = 1; x <= y; x++) { int rok; scanf("%d", &rok); t[y][x] = t[y-1][x-1] + t[y-1][x] + 1; if (y > 1) t[y][x] -= t[y-2][x-1]; debug << imie(t[y][x]) imie(rok); if (t[y][x] <= k) w = min(w, rok); } debug << "___"; } printf("%d\n", w); }
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #ifndef LOCAL #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> using namespace std; // to jest debug() << imie(a) << imie(b) << imie((char)c); #define R22(r) template <class c> typename enable_if<sizeof(dud<c>(0)) r,muu&>::type operator<<(c g) template <class c> struct rge {c b, e;}; template <class c> rge<c> range(c i, c j) {return rge<c>{i, j};} template <class c> auto dud(c*r)->decltype(cerr << *r); template <class c> char dud(...); struct muu { #ifdef LOCAL stringstream a; ~muu() {cerr << a.str() << endl;} R22(>=2) {a << boolalpha << g; return *this;} R22(==1) {return *this << range(begin(g), end(g));} template <class c > muu & operator<<( rge<c> u) { a << "["; for (c i = u.b; i != u.e; ++i) *this << ", " + 2 * (i == u.b) << *i; return *this << "]"; } template <class c, class m > muu & operator<<( pair <m,c> r) {return *this << "(" << r.first << ", " << r.second << ")";} #else template <class c > muu & operator<<( const c&){return *this;} #endif muu & operator()(){return *this;} }; #define imie(r) "[" #r ": " << (r) << "] " #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ") // to jest dodawanie par, mozna ominac template<typename T, typename S> pair<T, S> operator+(pair<T,S> a, pair<T,S>b) {return {a.first+b.first, a.second+b.second};} template<typename T> T& mini(T& a, T b) { return b < a ? a=b : a; } template<typename T> T& maxi(T& a, T b) { return b > a ? a=b : a; } using ll = long long; using ull = unsigned long long; using ld = long double; using pld = pair<ld, ld>; using pii = pair<int, int>; const int MAXN = 2001; int t[MAXN][MAXN]; int main() { int n,k; scanf("%d%d", &n, &k); int w = 1e9; for (int y = 1; y <= n; y++) { for (int x = 1; x <= y; x++) { int rok; scanf("%d", &rok); t[y][x] = t[y-1][x-1] + t[y-1][x] + 1; if (y > 1) t[y][x] -= t[y-2][x-1]; debug << imie(t[y][x]) imie(rok); if (t[y][x] <= k) w = min(w, rok); } debug << "___"; } printf("%d\n", w); } |