0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:28:47 +00:00
Baoshuo Ren 2022-08-06 15:59:08 +08:00
parent fcc16cfeb0
commit 3bb90b57d0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

53
Gym/103860/F/F.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 22;
int n;
long long a[N], x, ans;
bool vis[N];
void dfs(int idx, long long now, int cnt) {
if (now < ans) return;
if (cnt == n || now < a[1]) {
ans = std::max(ans, now);
return;
}
vis[idx] = true;
for (int i = 1; i <= n; i++) {
if (now < a[i]) break;
if (vis[i]) continue;
dfs(i, now % a[i], cnt + 1);
}
vis[idx] = false;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> x;
std::sort(a + 1, a + 1 + n);
dfs(0, x, 0);
cout << ans << endl;
return 0;
}