#include using namespace std; void chmax(int64_t& a, int64_t b){ a = max(a, b); } void chmin(int64_t& a, int64_t b){ a = min(a, b); } int main(){ int K; int64_t N; cin >> K >> N; vector A(2*K), B(K); for(int i=0; i> A[i]; for(int i=0; i> B[i]; const int64_t INF = 1e18; // 最初にA[2K-1]まで求めてしまう for(int i=K; i<2*K; i++){ int64_t mx = -INF; for(int j=0; j= x かどうかを返す auto check = [&](int64_t x)->bool{ vector S, T; for(int i=K; i<2*K; i++) if(A[i] >= x) S.push_back(i); for(int i=0; i= x) T.push_back(K-i); if(T.size() == 0) return false; // ダイクストラ法 int m = T[0]; vector D(m, INF+1); for(int s : S) chmin(D[s%m], s); vector done(m); while(true){ int s = -1; for(int i=0; i D[i]) s = i; if(s == -1) break; for(int t : T) chmin(D[(s+t)%m], D[s] + t); done[s] = true; } return (D[N%m] <= N); }; int64_t ok = -INF, ng = INF+1; while(ng-ok>1){ int64_t mid = (ok+ng)/2; (check(mid) ? ok : ng) = mid; } cout << ok << endl; return 0; }