#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll X_MAX = 2000*2000 + 5; ll n; ll k; ll A [ X_MAX ] [ 2 ]; ll t [ X_MAX ]; ll toUnblock [ X_MAX ]; ll nrVertex; ll numberOfElements; void showNeighbours() { for ( ll i = 1; i <= numberOfElements; i++ ) { cout << i << ": "; if ( A [ i ] [ 0 ] == 0 ) { cout << "brak" << '\n'; } else { cout << A [ i ] [ 0 ] << ' ' << A [ i ] [ 1 ] << '\n'; } } } void showToUnblock() { ll x = 0; for ( ll i = 1; i <= n; i++ ) { for ( ll j = 1; j <= i; j++ ) { x++; cout << toUnblock [ x ] << " "; } cout << '\n'; } cout << '\n'; cout << '\n'; } void showt() { ll x = 0; for ( ll i = 1; i <= n; i++ ) { for ( ll j = 1; j <= i; j++ ) { x++; cout << t [ x ] << " "; } cout << '\n'; } cout << '\n'; cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin >> n >> k; numberOfElements = (n*(n+1))/2; //utworzenie grafu for ( ll i = 1; i <= n; i++ ) { for ( ll j = 1; j <= i; j++ ) { nrVertex++; cin >> t [ nrVertex ]; if ( i != n ) { A [ nrVertex ] [ 0 ] = nrVertex + i; A [ nrVertex ] [ 1 ] = nrVertex + i + 1; } } } ll i = 1; ll a = 1; ll b = -1; ll j = -1; toUnblock [ 1 ] = -1; while ( true ) { b = a + 1; j = i; toUnblock [ i ] = toUnblock [ i - a + 1 ] + 1; if ( i == 1 ) { toUnblock [ i ] = 0; } /*cout << "a: " << a << '\n'; cout << "i: " << i << " " << "poprzedni: " << i - a + 1 << '\n'; cout << i << ": " << toUnblock [ i ] << '\n'; cout << '\n';*/ while ( true ) { if ( i != j ) { toUnblock [ j ] = toUnblock [ j - b + 1 ] + a; } //ide dalej w prawo j += b; b++; if ( j > numberOfElements ) { break; } } //ide dalej w lewo i += a; a++; if ( i > numberOfElements) { break; } } ll res = 3000; for ( ll i = 1; i <= numberOfElements; i++ ) { if ( toUnblock [ i ] <= k ) { res = min(t [ i ], res ); } } cout << res << '\n'; //showt(); //showToUnblock(); return 0; } /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll X_MAX = 2000*2000 + 5; ll n; ll k; ll A [ X_MAX ] [ 2 ]; ll t [ X_MAX ]; ll toUnblock [ X_MAX ]; ll nrVertex; ll numberOfElements; void showNeighbours() { for ( ll i = 1; i <= numberOfElements; i++ ) { cout << i << ": "; if ( A [ i ] [ 0 ] == 0 ) { cout << "brak" << '\n'; } else { cout << A [ i ] [ 0 ] << ' ' << A [ i ] [ 1 ] << '\n'; } } } void showToUnblock() { ll x = 0; for ( ll i = 1; i <= n; i++ ) { for ( ll j = 1; j <= i; j++ ) { x++; cout << toUnblock [ x ] << " "; } cout << '\n'; } cout << '\n'; cout << '\n'; } void showt() { ll x = 0; for ( ll i = 1; i <= n; i++ ) { for ( ll j = 1; j <= i; j++ ) { x++; cout << t [ x ] << " "; } cout << '\n'; } cout << '\n'; cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin >> n >> k; numberOfElements = (n*(n+1))/2; //utworzenie grafu for ( ll i = 1; i <= n; i++ ) { for ( ll j = 1; j <= i; j++ ) { nrVertex++; cin >> t [ nrVertex ]; if ( i != n ) { A [ nrVertex ] [ 0 ] = nrVertex + i; A [ nrVertex ] [ 1 ] = nrVertex + i + 1; } } } ll i = 1; ll a = 1; ll b = -1; ll j = -1; toUnblock [ 1 ] = -1; while ( true ) { b = a + 1; j = i; toUnblock [ i ] = toUnblock [ i - a + 1 ] + 1; if ( i == 1 ) { toUnblock [ i ] = 0; } /*cout << "a: " << a << '\n'; cout << "i: " << i << " " << "poprzedni: " << i - a + 1 << '\n'; cout << i << ": " << toUnblock [ i ] << '\n'; cout << '\n';*/ while ( true ) { if ( i != j ) { toUnblock [ j ] = toUnblock [ j - b + 1 ] + a; } //ide dalej w prawo j += b; b++; if ( j > numberOfElements ) { break; } } //ide dalej w lewo i += a; a++; if ( i > numberOfElements) { break; } } ll res = 3000; for ( ll i = 1; i <= numberOfElements; i++ ) { if ( toUnblock [ i ] <= k ) { res = min(t [ i ], res ); } } cout << res << '\n'; //showt(); //showToUnblock(); return 0; } /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ |