text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
vector<int> vc, ans;
set<int> ans1;
set<int>::iterator it;
int main() {
long n, l, r, f1, f2;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
vc.push_back(x);
}
for (int i = 0; i < n; i++) {
int diff = min(abs(1 - vc[i]), abs(1000000 - vc[i]));
ans.push_back(diff);
}
sort(ans.begin(), ans.end());
cout << ans[ans.size() - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int mod = 1e9 + 7;
int a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
const int mil = 1e6;
int res = min(a[n] - 1, mil - a[1]);
for (int i = 1; i < n; ++i) res = min(res, max(a[i] - 1, mil - a[i + 1]));
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[2000000];
int main() {
long long int n;
cin >> n;
for (long long int j = 0; j < n; j++) {
long long int num;
cin >> num;
a[num] = -1;
}
long long int r = 1, m = 1000000;
long long int t = 0, i = 0;
while (i < n) {
t++;
if (a[++r] == -1) i++;
if (a[--m] == -1) i++;
}
cout << t;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
ans = max(ans, min(a[i] - 1, 1000000 - a[i]));
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000006];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int ans = 1000000 - a[0];
a[n] = 1000000;
for (int i = 0; i < n; i++) {
ans = min(ans, max((a[i] - 1), 1000000 - a[i + 1]));
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926536;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int k = 0, s = 0;
for (int i = 0; i <= 1000000 / 2; i++) {
if (a[k] == i && k < n) {
s = a[k] - 1;
k++;
}
}
k = n - 1;
int c = 0;
for (int i = 1000000; i > 1000000 / 2; i--) {
if (i == a[k] && k >= 0) {
c = 1000000 - a[k];
k--;
}
}
cout << max(c, s);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, x, ans;
ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> x;
ans = max(ans, min(x - 1, 1000000 - x));
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long be(long long a, long long b, long long mod) {
if (b == 0) return 1;
if (b % 2 == 1)
return (a * be(a, b - 1, mod)) % mod;
else
return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod;
}
const long long mod = 998244353;
const long long siz = 2 * (1e5 + 1);
const long long logi = 21;
const double epsilon = 1e-6;
long long prime[siz];
bool cmp(const long long &a, const long long &b) { return (abs(a - b) > 1); }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
t = 1;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long f = 1e6;
long long ans = INT_MAX;
for (long long i = 0; i < n; i++) {
long long d1 = INT_MIN;
long long d2 = INT_MIN;
d1 = a[i] - 1;
if (i + 1 < n) {
d2 = f - a[i];
}
ans = min(ans, max(d1, d2));
}
for (long long i = n - 1; i >= 0; i--) {
long long d1 = INT_MIN;
long long d2 = INT_MIN;
if (i - 1 >= 0) {
d1 = a[i - 1] - 1;
}
d2 = f - a[i];
ans = min(ans, max(d1, d2));
}
cout << ans << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int res = numeric_limits<int>::max();
for (int i = 1; i <= n; ++i) {
res = min(res, max(a[i] - 1, 1000000 - a[i + 1]));
}
res = min(res, a[n] - 1);
res = min(res, 1000000 - a[1]);
cout << res;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int loc, curM;
int ans = 1;
while (n--) {
cin >> loc;
if (loc > 500000) {
curM = 1000000 - loc;
} else {
curM = loc - 1;
}
if (ans < curM) ans = curM;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 20;
const int MID = 5e5;
int a[MAXN];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
int t = upper_bound(a, a + n, MID) - a;
int t1, t2;
if (t - 1 >= 0)
t1 = a[t - 1] - 1;
else
t1 = 0;
if (t < n && a[t] >= MID)
t2 = 1e6 - a[t];
else
t2 = 0;
cout << max(t1, t2) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int64_t N = 1e3 + 3;
const int64_t mod = 998244353;
int64_t dx[] = {-1, 1, 0, 0};
int64_t dy[] = {0, 0, 1, -1};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int64_t n;
cin >> n;
int64_t a[n + 1];
for (int64_t i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
a[0] = 1;
a[n + 1] = 1e6;
int64_t ans = 1e9;
for (int64_t i = 0; i <= n; i++) {
ans = min(ans, max(a[i] - a[0], a[n + 1] - a[i + 1]));
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
int n, a, b, x, ar[MX];
string str;
char stt[] = {'a', 'e', 'i', 'o', 'u', 'y'};
bool isvowel(char ch) {
int k;
for (k = 0; k < 6; k++)
if (stt[k] == ch) {
break;
}
if (k == 6) return 0;
return 1;
}
int main() {
while (cin >> n) {
for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
if (n == 1) {
printf("%d\n", min(ar[0] - 1, 1000000 - ar[0]));
continue;
}
int ans = min(1000000 - ar[0], ar[n - 1] - 1);
for (int i = 0; i < n; i++) {
if (i + 1 < n) ans = min(ans, max(ar[i] - 1, 1000000 - ar[i + 1]));
if (i - 1 >= 0) ans = min(ans, max(ar[i - 1] - 1, 1000000 - ar[i]));
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n], l = 0, k = 0, sum = 0, p = 1000000;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum = max(sum, min(a[i] - 1, p - a[i]));
}
cout << sum;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int INF = 1e9 + 9;
int n;
vector<int> a;
void ReadInput() {
cin >> n;
a.resize(n + 2);
for (int i = 1; i <= n; ++i) cin >> a[i];
a[0] = 1;
a[n + 1] = 1e6;
sort(a.begin(), a.end());
}
void Solve() {
int l = 1, r = 1e6;
int ans = INF;
for (int i = 0; i <= n; ++i) ans = min(ans, max(a[i] - l, r - a[i + 1]));
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 5;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long ans = 0;
long long temp = 1e6;
for (long long i = 0; i < n; ++i) {
long long x;
cin >> x;
ans = max(ans, min(x - 1, temp - x));
}
cout << ans << '\n';
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> vect(n + 2);
for (int i = 1; i <= n; i++) {
cin >> vect[i];
}
long maxm = *max_element(vect.begin(), vect.end());
long res = INT_MAX;
vect[0] = 1;
vect[n + 1] = 1000000;
for (int i = 0; i <= n; i++) {
res = min(res, max(vect[i] - vect[0], vect[n + 1] - vect[i + 1]));
}
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int dis[N], in, ans = 1e9, n;
int main() {
scanf("%d", &n);
dis[0] = 1;
dis[n + 1] = 1e6;
for (int i = 1; i <= n; i++) scanf("%d", dis + i);
for (int i = 1; i <= n; i++)
ans = min(ans, max(dis[i] - 1, dis[n + 1] - dis[i + 1]));
ans = min(ans, min(dis[n] - 1, dis[n + 1] - dis[1]));
printf("%d\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, pas = 10000000;
cin >> n;
int a[n];
a[n + 1] = 1000000;
a[0] = 1;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 0; i <= n; i++)
pas = min(pas, max(a[i] - 1, 1000000 - a[i + 1]));
cout << pas;
return 0;
}
|
#include <bits/stdc++.h>
long long int a[1000005];
long long int b[1000005];
int main() {
long long int n;
long long int i = 0;
long long int j = 0;
long long int k;
long long int p;
long long int temp1 = 0;
long long int temp2 = 0;
scanf("%lld", &n);
for (p = 0; p < n; p++) {
scanf("%lld", &k);
if (k <= 500000)
a[i++] = k;
else if (k > 500000)
b[j++] = k;
}
if (i != 0) {
temp1 = a[0] - 1;
for (p = 1; p < i; p++) {
temp1 += a[p] - a[p - 1];
}
}
if (j != 0) {
temp2 = 1000000 - b[j - 1];
for (p = j - 1; p >= 1; p--) {
temp2 += b[p] - b[p - 1];
}
}
if (temp1 > temp2)
printf("%lld\n", temp1);
else
printf("%lld\n", temp2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100006];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
int maxx = 0, minn = 1000005;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] <= 500000 && a[i] >= maxx)
maxx = a[i];
else if (a[i] >= 500000 && a[i] <= minn)
minn = a[i];
}
int t = max(maxx - 1, 1000000 - minn);
cout << t << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool wayToSort(string s1, string s2) {
if (s1.length() < s2.length()) return true;
if (s2.length() < s1.length())
return false;
else
return (s1 < s2);
}
bool is_vow(char a) {
char vow[5] = {'a', 'e', 'i', 'o', 'u'};
for (int i = 0; i < 5; i++)
if (vow[i] == a) return true;
return false;
}
vector<int> a;
int main() {
int n;
cin >> n;
int temp;
for (int i = 0; i < n; i++) {
cin >> temp;
a.push_back(temp);
}
int ans = 0, dist1 = 0, dist2 = 0;
for (int i = 0; i < n; i++) {
dist1 = a[i] - 1;
dist2 = 1000000 - a[i];
int ans1 = min(dist1, dist2);
if (ans < ans1) ans = ans1;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
const long long M = 1000;
const long long N = 1020000;
const long long mx = (1e18);
using namespace std;
long long x, y, a[N], n, m, k, l, w, j, i, res, w1, w2;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
x = 1;
y = (1e6);
w1 = w2 = 0;
for (i = 1; i <= n; i++) w = max(w, min(abs(x - a[i]), abs(y - a[i])));
cout << w;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, ans = 0;
cin >> n;
for (int i = int(0); i < int(n); ++i) {
cin >> x;
ans = max(ans, min(x - 1, 1000000 - x));
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
if (y == 0)
return 1;
else {
long long int p = power(x, y / 2);
if (y % 2 == 0)
return (p * p) % 1000000007LL;
else
return (x * ((p * p) % 1000000007LL)) % 1000000007LL;
}
}
long long int gcd(long long int x, long long int y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long int m = a[n - 1] - 1;
m = min(m, 1000000 - a[0]);
for (int i = 0; i < n - 1; i++) {
long long int x = a[i] - 1;
long long int y = 1000000 - a[i + 1];
m = min(m, max(x, y));
}
cout << m;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000000 + 6], n, ans = 1000000 + 6;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
a[0] = 1;
a[n + 1] = 1000000;
for (int i = 0; i <= n; i++)
ans = min(ans, max(a[i] - 1, 1000000 - a[i + 1]));
printf("%d", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t1 = 0, t2 = 0;
int a[1000000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
if (a[i] <= 500000) t1 = a[i] - 1;
}
for (int i = n - 1; i >= 0; i--) {
if (a[i] > 500000) t2 = 1000000 - a[i];
}
if (t1 > t2)
cout << t1 << endl;
else
cout << t2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 1, b, c = 0, d = 0, e = 0, f, i = 0, k = 0, j = 0, n = 0, t = 0,
l = 0, m = 0, h[3000] = {0};
string s, x;
cin >> t;
n = 1000000;
for (i = 0; i < t; i++) {
cin >> b;
j = max(j, min(b - 1, 1000000 - b));
}
cout << j;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main(int argc, char const *argv[]) {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
int res = 1000000 - a[0];
for (int i = 0; i < n; ++i) {
int temp = a[i] - 1;
if (i != n - 1) {
temp = max(temp, 1000000 - a[i + 1]);
}
res = min(temp, res);
}
printf("%d\n", res);
}
return 0;
}
|
#include <bits/stdc++.h>
int n, s[1000005], i, a = 1000000, m = 1000000, l;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &s[i]);
}
s[0] = 1;
s[n + 1] = a;
for (i = 0; i <= n; i++) {
l = (s[i] - 1 > a - s[i + 1]) ? s[i] - 1 : a - s[i + 1];
if (m > l) {
m = l;
}
}
printf("%d", m);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1e5 + 1;
const int last = 1e6;
int a[SIZE];
int main() {
ios::sync_with_stdio(false);
int i, n, b = 0, c = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
int left = 0, right = n - 1;
while (left < right) {
if (a[left] - 1 < last - a[right]) {
left++;
} else {
right--;
}
}
cout << min(a[left] - 1, last - a[right]) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double PI = 3.141592653589793;
int main() {
ios_base::sync_with_stdio(false);
long long int n, ans = 0, a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
ans = max(ans, min(a - 1, 1000000 - a));
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool cmpf(float a, float b, float epsilon) {
return (fabs(a - b) <= epsilon * max(fabs(a), fabs(b)));
}
long long int fpow(long long int n, long long int k, long long int p) {
long long int r = 1;
for (; k; k >>= 1) {
if (k & 1) r = r * n % p;
n = n * n % p;
}
return r;
}
long long int inv(long long int a, long long int p) {
return fpow(a, p - 2, p);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t, n, m, k, d, di, ti, si, cnt, temp, i, j, l, r;
cin >> n;
std::vector<long long int> v1, v2;
for (i = 0; i < n; i++) {
cin >> m;
if (m <= 500000)
v1.push_back(m);
else
v2.push_back(1000001 - m);
}
ti = 0;
di = 0;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
if (v1.size() != 0) ti = v1[v1.size() - 1];
if (v2.size() != 0) di = v2[v2.size() - 1];
cout << max(ti, di) - 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int c = 1000000;
int* a = new int[n];
for (int i = 0; i < n; ++i) cin >> a[i];
int max_ = 0, min_ = c;
for (int i = 0; i < n; ++i) {
if (a[i] <= c / 2) {
max_ = a[i];
} else {
min_ = a[i];
break;
}
}
cout << max(max_ - 1, c - min_) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> prizes;
int main() {
int n;
cin >> n;
int prize_idx;
for (int i = 0; i < n; i++) {
cin >> prize_idx;
prizes.push_back(prize_idx);
}
int my_loc = 1, friend_loc = 1000000;
int my_time = 0, friend_time = 0;
int left_prize = 0, right_prize = n - 1;
while (right_prize - left_prize > -1) {
if (my_time + (prizes[left_prize] - my_loc) <
friend_time + (friend_loc - prizes[right_prize])) {
my_time += (prizes[left_prize] - my_loc);
my_loc = prizes[left_prize];
left_prize++;
} else {
friend_time += (friend_loc - prizes[right_prize]);
friend_loc = prizes[right_prize];
right_prize--;
}
}
cout << max(my_time, friend_time) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int v[101010];
int main() {
cin >> n;
int lst = 1;
for (int i = 0; i < n; i++) {
cin >> v[i];
int a = v[i] - 1;
int b = 1e6 - v[i];
if (a > b) {
cout << max(lst - 1, (int)1e6 - v[i]) << endl;
return 0;
}
lst = v[i];
}
cout << v[n - 1] - 1 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const int maxm = 1000000 + 10;
const int mod = (int)1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 62);
const double eps = 1e-9;
const double PI = acos(-1.0);
int a[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
a[0] = 1;
a[n + 1] = 1e6;
int ans = INF;
for (int i = 0; i <= n; i++) {
ans = min(ans, max(a[i] - 1, (int)1e6 - a[i + 1]));
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m;
int max = 0;
for (int i = 1; i <= n; i++) {
cin >> m;
if (m > 500000) {
m = 1000000 - m + 1;
}
if (m >= max) {
max = m;
}
}
cout << max - 1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int t1 = 0;
long long int tm1 = 0;
long long int t2 = 0;
long long int tm2 = 0;
long long int a;
for (int i = 0; i < n; i++) {
cin >> a;
if (a <= 1000000 / 2) {
t1 = a - 1;
tm1 = max(t1, tm1);
} else {
t2 = 1000000 - a;
tm2 = max(t2, tm2);
}
}
cout << max(tm1, tm2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 5;
int a[M];
int main() {
int n, m;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> m;
a[m] = 1;
}
int my = 1, fr = 1e6, cnt = 0, time = 0;
while (cnt != n) {
my++;
fr--;
if (a[my]) {
cnt++;
}
if (my != fr && a[fr]) {
cnt++;
}
time++;
}
cout << time << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main() {
int n;
cin >> n;
int t1 = 0, t2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] <= 1000000 / 2)
t1 = max(t1, a[i] - 1);
else
t2 = max(t2, abs(1000000 - a[i]));
}
cout << max(t1, t2) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100009], bb[1000009];
vector<long long> vc;
map<long long, long long> mp;
map<long long, long long> mp1;
int main() {
cin.sync_with_stdio(false);
long long i, j, k, l, c, v, b, bv[1000], aa[1009], bb1[1000], n, m, r, t, e,
f;
long long x1, x2, y1, y2, x3, x4, x5, x6;
string s, s1, s2, s3, ss[10000];
while (cin >> n) {
k = l = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (i = 0; i < n; i++) {
if (a[i] <= 500000) {
l = a[i] - 1;
} else {
break;
}
}
for (i = n - 1; i >= 0; i--) {
if (a[i] <= 500000) {
break;
} else {
k = 1000000 - a[i];
}
}
cout << (max(k, l));
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int ans = 0;
for (int i = (1); i <= (n); i++) {
int num;
cin >> num;
ans = max(ans, min(num - 1, 1000000 - num));
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, pos, num[100005];
cin >> n;
for (i = 1; i <= n; i++) scanf("%d", &num[i]);
pos = upper_bound(num + 1, num + 1 + n, 5e5) - num;
if (pos > n)
cout << num[n] - 1 << endl;
else if (pos <= 1)
cout << 1e6 - num[1] << endl;
else {
cout << max((int)1e6 - num[pos], num[pos - 1] - 1) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) {
cin >> v[i];
}
long long int ans = -1;
for (long long int i = 0; i < n; i++) {
v[i] = min(v[i] - 1, 1000000 - v[i]);
ans = max(ans, v[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, arr[1000001];
int main() {
cin >> n;
int tem;
for (int i = 0; i < n; i++) {
cin >> tem;
arr[tem] = 1;
}
int i_f = 0, j_f = 0;
for (int i = 500000, j = i + 1;; i--, j++) {
if (arr[i] == 1 && i_f == 0) {
i_f = i;
}
if (arr[j] == 1 && j_f == 0) {
j_f = j;
}
if (i_f && j_f) break;
}
printf("%d", max(i_f - 1, 1000000 - j_f));
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> ve;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
ve.push_back(x);
}
vector<int> res;
for (int i = 0; i < n; i++) {
res.push_back(min(ve[i] - 1, (int)1e6 - ve[i]));
}
cout << *max_element(res.begin(), res.end()) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long sum, fsum;
long long arr[1000005];
int main(void) {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &k);
arr[k] = 1;
}
for (int i = 500000; i >= 1; i--) {
if (arr[i]) {
sum = i - 1;
break;
}
}
for (int i = 500001; i <= 1000000; i++) {
if (arr[i]) {
fsum = 1000000 - i;
break;
}
}
if (sum < fsum) sum = fsum;
printf("%lld", sum);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a;
a.resize(n);
for (int i = 0; i < (n); i++) cin >> a[i];
int ans = INT_MAX;
ans = min(ans, a[n - 1] - 1);
ans = min(ans, 1000000 - a[0]);
for (int i = 0; i < n - 1; i++) {
ans = min(ans, max(a[i] - 1, 1000000 - a[i + 1]));
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 1e6 + 1e4, MOD = 1e9 + 7, MAXL = 25;
void OUT(long double o, int x) {
cout << fixed << setprecision(x) << o;
return;
}
long long a[MAX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
a[x] = 1;
}
long long x = 0;
for (int i = 1; i < 500000; i++) {
if (a[1 + i] || a[1000000 - i]) x = i;
}
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int M = 1e6;
int a[N + 5], n;
int s = 1, t = M;
int ans = M;
int main() {
scanf("%d", &n);
a[0] = 1, a[n + 1] = M;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 0; i <= n; i++) ans = min(ans, max(a[i] - s, t - a[i + 1]));
printf("%d", ans);
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, x = 1, y = 1000000, s1 = 0, s2 = 0, z;
scanf("%d", &n);
while (n > 0) {
scanf("%d", &z);
if (z <= 1000000 / 2) {
x = z;
} else {
if (y > z) {
y = z;
}
}
n--;
}
if ((x - 1) > 1000000 - y) {
printf("%d", x - 1);
} else {
printf("%d", 1000000 - y);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0, s1 = 0, s = 0, l = 0, m, sec;
cin >> n;
m = n - 1;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 2, k = 999999; c != n; i++, k--) {
if (i == a[l]) {
s1 = i - 2 + 1;
c++;
l++;
}
if (k == a[m]) {
s = 1000000 - k;
c++;
m--;
}
}
if (s > s1)
sec = s;
else
sec = s1;
cout << sec;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 + 1;
const int N = (int)1e5 + 77;
const long long mod = (long long)1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, a[N], k = (int)1e6;
cin >> n;
for (int i = 0; i < (int)(n); ++i) cin >> a[i];
int m = min(k - a[0], a[n - 1] - 1);
for (int i = 0; i < (int)(n - 1); ++i) {
m = min(m, max(a[i] - 1, k - a[i + 1]));
}
cout << m << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int M = 1e6 / 2;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N];
bool mark[N];
void read_input() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mark[a[i]] = true;
}
for (int i = 1; i < M; i++) {
if (mark[M + i] || mark[M - i + 1]) {
tmp = i;
cout << M - tmp;
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
read_input();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T &x) {
return x * x;
}
inline long long sqr(int x) { return sqr<long long>(x); }
template <class T>
T binpow(const T &a, long long n) {
return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1);
}
long long binpow(long long a, long long n, long long modulo) {
return n == 0 ? 1
: sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) %
modulo;
}
long long gcd(long long a, long long b, long long &x, long long &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
long long x1, y1;
long long d = gcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return d;
}
inline long long phi(long long n) {
long long result = n;
for (long long i = 2; i * i <= n; ++i)
if (n % i == 0) {
while (n % i == 0) n /= i;
result -= result / i;
}
if (n > 1) result -= result / n;
return result;
}
inline vector<long long> inverseAll(long long m) {
vector<long long> r(m);
r[1] = 1;
for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m;
return r;
}
inline long long gcd(long long a, long long b) { return gcd(a, b, a, b); }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long llrand() {
const long long lsbToFill = (sizeof(long long) << 3) - 1;
const long long bitsFilledInIteration = __builtin_popcountll(RAND_MAX);
long long number = 0;
for (long long lsbFilled = 0; lsbFilled <= lsbToFill;
lsbFilled += bitsFilledInIteration) {
number ^= (((long long)rand()) << lsbFilled);
}
return number & numeric_limits<long long>::max();
}
inline long long llrand(long long begin, long long end) {
return begin + llrand() % (end - begin);
}
struct Dinic {
struct Edge {
int u, v;
long long cap, flow;
Edge() {}
Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
};
int N;
vector<Edge> E;
vector<vector<int>> g;
vector<int> d, pt;
Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
void AddEdge(int u, int v, long long cap) {
if (u != v) {
E.emplace_back(Edge(u, v, cap));
g[u].emplace_back(E.size() - 1);
E.emplace_back(Edge(v, u, 0));
g[v].emplace_back(E.size() - 1);
}
}
bool BFS(int S, int T) {
queue<int> q({S});
fill(d.begin(), d.end(), N + 1);
d[S] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
if (u == T) break;
for (int k : g[u]) {
Edge &e = E[k];
if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
d[e.v] = d[e.u] + 1;
q.emplace(e.v);
}
}
}
return d[T] != N + 1;
}
long long DFS(int u, int T, long long flow = -1) {
if (u == T || flow == 0) return flow;
for (int &i = pt[u]; i < g[u].size(); ++i) {
Edge &e = E[g[u][i]];
Edge &oe = E[g[u][i] ^ 1];
if (d[e.v] == d[e.u] + 1) {
long long amt = e.cap - e.flow;
if (flow != -1 && amt > flow) amt = flow;
if (long long pushed = DFS(e.v, T, amt)) {
e.flow += pushed;
oe.flow -= pushed;
return pushed;
}
}
}
return 0;
}
long long MaxFlow(int S, int T) {
long long total = 0;
while (BFS(S, T)) {
fill(pt.begin(), pt.end(), 0);
while (long long flow = DFS(S, T)) total += flow;
}
return total;
}
};
vector<long long> Dijkstra(const vector<list<pair<int, long long>>> &g, int s) {
vector<long long> d(int((g).size()), numeric_limits<long long>::max() / 2LL);
priority_queue<pair<long long, int>> q;
d[s] = 0;
q.emplace(-0, s);
while (!q.empty()) {
while (q.top().first > d[q.top().second]) {
q.pop();
}
int v = q.top().second;
q.pop();
for (const auto &cw : g[v]) {
if (d[v] + cw.second < d[cw.first]) {
d[cw.first] = d[v] + cw.second;
q.emplace(-d[cw.first], cw.first);
}
}
}
return d;
}
struct BinarySearchIterator
: public std::iterator<std::forward_iterator_tag, bool> {
long long value;
typename iterator_traits<BinarySearchIterator>::difference_type operator-(
const BinarySearchIterator &it) const {
return value - it.value;
}
BinarySearchIterator &operator++() {
++value;
return *this;
}
bool operator!=(const BinarySearchIterator &it) const {
return value != it.value;
}
bool operator*() const { return true; }
};
template <int ALPHA>
class AhoCorasick {
public:
static const int ILLEGAL_INDEX;
static const int ROOT;
struct Node {
bool leaf;
int parent;
int parentCharacter;
int link;
int next[ALPHA];
int go[ALPHA];
int outputFunction;
Node(int parent = ILLEGAL_INDEX, int parentCharacter = ALPHA)
: leaf(false),
parent(parent),
parentCharacter(parentCharacter),
link(ILLEGAL_INDEX),
outputFunction(ILLEGAL_INDEX) {
fill_n(next, ALPHA, ILLEGAL_INDEX);
fill_n(go, ALPHA, ILLEGAL_INDEX);
}
};
vector<Node> tree = vector<Node>(1);
AhoCorasick() {}
AhoCorasick(int maxStatesNumber) { tree.reserve(maxStatesNumber); }
template <class Iterator>
void add(int length, const Iterator begin) {
int vertex = ROOT;
for (int i = 0; i < length; ++i) {
if (ILLEGAL_INDEX == tree[vertex].next[begin[i]]) {
tree[vertex].next[begin[i]] = int((tree).size());
tree.push_back(Node(vertex, begin[i]));
}
vertex = tree[vertex].next[begin[i]];
}
tree[vertex].leaf = true;
}
int getLink(int vertex) {
assert(0 <= vertex && vertex < tree.size());
if (ILLEGAL_INDEX == tree[vertex].link) {
if (ROOT == vertex || ROOT == tree[vertex].parent) {
tree[vertex].link = ROOT;
} else {
tree[vertex].link =
go(getLink(tree[vertex].parent), tree[vertex].parentCharacter);
}
}
return tree[vertex].link;
}
int go(int vertex, int character) {
assert(0 <= character && character < ALPHA);
assert(0 <= vertex && vertex < tree.size());
if (ILLEGAL_INDEX == tree[vertex].go[character]) {
if (ILLEGAL_INDEX == tree[vertex].next[character]) {
tree[vertex].go[character] =
ROOT == vertex ? ROOT : go(getLink(vertex), character);
} else {
tree[vertex].go[character] = tree[vertex].next[character];
}
}
return tree[vertex].go[character];
}
int getOutputFunction(int vertex) {
assert(0 <= vertex && vertex < tree.size());
if (ILLEGAL_INDEX == tree[vertex].outputFunction) {
if (tree[vertex].leaf || ROOT == vertex) {
tree[vertex].outputFunction = vertex;
} else {
tree[vertex].outputFunction = getOutputFunction(getLink(vertex));
}
}
return tree[vertex].outputFunction;
}
};
template <int ALPHA>
const int AhoCorasick<ALPHA>::ILLEGAL_INDEX = -1;
template <int ALPHA>
const int AhoCorasick<ALPHA>::ROOT = 0;
int main(int argc, const char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
srand((unsigned int)time(NULL));
int n;
while (cin >> n) {
vector<int> a(n);
for (int i = (0); i < (n); ++i) {
cin >> a[i];
}
int answer = min(a[n - 1] - 1, (int)1e6 - a[0]);
for (int i = (0); i < (n - 1); ++i) {
answer = min(answer, max((int)1e6 - a[i + 1], a[i] - 1));
}
cout << answer << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n], i, ans = 0;
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 0; i < n; ++i)
if (a[i] <= 5 * 100000)
ans = max(ans, a[i] - 1);
else
ans = max(ans, 1000000 - a[i]);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
long long a[n + 2];
for (long long i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
long long ans = a[n] - 1;
ans = min(ans, 1000000 - a[1]);
for (long long i = 1; i <= n - 1; i++) {
ans = min(ans, max(a[i] - 1, 1000000 - a[i + 1]));
}
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int time_to_pick(int k) { return min(abs(k - 1), abs(1000000 - k)); }
int main() {
int n;
cin >> n;
vi prizes(n);
int seconds = 0;
for (int i = 0; i < n; i++) {
cin >> prizes[i];
seconds = max(seconds, time_to_pick(prizes[i]));
}
cout << seconds << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2 * 1e9 + 100;
const long long M = 1e2 + 100;
const long long N = 1e6 + 100;
long long a[N];
vector<long long> v1, v2;
int main() {
long long n;
cin >> n;
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long t1 = 0, t2 = 0;
for (long long i = 0; i < n; i++) {
if (a[i] <= 500000)
v1.push_back(a[i]);
else
v2.push_back(a[i]);
}
sort(v1.rbegin(), v1.rend());
sort(v2.begin(), v2.end());
t1 = (v1.empty() ? -INF : v1[0] - 1),
t2 = (v2.empty() ? -INF : 1000000 - v2[0]);
cout << max(t1, t2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] = min(a[i] - 1, 1000000 - a[i]);
}
sort(a + 1, a + 1 + n);
cout << a[n] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
float PHI = 1.6180339;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
long long n;
cin >> n;
long long arr[n + 10];
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
long long tot = 0;
long long first = 1;
long long last = 1000000;
long long j = n - 1;
long long ans = INT_MIN;
for (long long i = 0; i <= n - 1; i++) {
long long diff1 = abs(arr[i] - first);
long long diff2 = abs(arr[i] - last);
long long diff3 = abs(arr[j] - first);
long long diff4 = abs(arr[j] - last);
ans = max(ans, min((arr[i] - 1), last - arr[i]));
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i = 1;
int y = 1000000;
int n, j, arr;
cin >> n;
int ans = 0;
while (n--) {
cin >> arr;
ans = max(ans, min(arr - i, y - arr));
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
t = 1;
while (t--) {
int n;
cin >> n;
int min1 = 0, min2 = 0;
for (int i = 0; i < n; i++) {
int u;
cin >> u;
if (u <= 500000 && min1 < u) {
min1 = u - 1;
}
if (u > 500000 && min2 < 1000000 - u) {
min2 = 1000000 - u;
}
}
cout << max(min1, min2);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
ans = max(ans, min(abs(1 - x), abs(1000000 - x)));
}
printf("%d", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long ans1 = 0;
long long ans2 = 0;
vector<int> v;
cin >> n;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
v.push_back(x);
}
long long k = 1;
long long j = 1000000;
for (int i = 0; i < n; i++) {
if (abs(k - v[i]) < abs(j - v[i])) {
ans1 = v[i] - 1;
} else {
ans2 = 1000000 - (v[i]);
break;
}
}
cout << max(ans1, ans2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int n;
int tmp, max_elem, ans;
bool flag = true;
int ind = 0;
int main() {
max_elem = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> tmp;
a.push_back(tmp);
}
for (int i = 0; i <= n - 1; i++) {
if (a[i] <= 500000) {
tmp = a[i] - 1;
} else {
tmp = 1000000 - a[i];
}
if (tmp > max_elem) {
max_elem = tmp;
}
}
cout << max_elem;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int a[100 * 1000 + 228];
signed main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
int res = min(a[n] - 1, 1000 * 1000 - a[1]);
for (int i = 1; i < n; ++i) {
res = min(res, max(a[i] - 1, 1000 * 1000 - a[i + 1]));
}
cout << res << "\n";
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, a, b, min, max = 0;
scanf("%d", &n);
int data[n], i;
for (i = 0; i < n; i++) {
scanf("%d", &data[i]);
a = data[i] - 1;
b = 1000000 - data[i];
if (a < b)
min = a;
else
min = b;
if (min > max) max = min;
}
printf("%d", max);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e = 1000000 / 2, t[100005], maxx, minn = 11111111, ans;
int main() {
scanf("%d", &a);
for (int x = 0; x < a; x++) {
scanf("%d", &t[x]);
if (t[x] <= e) {
maxx = max(t[x], maxx);
} else {
minn = min(t[x], minn);
}
}
int u = 1e6 - minn;
ans = max(u, maxx - 1);
printf("%d", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a, c[1000005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
c[a]++;
}
int sol = 0, p1 = 1, p2 = 1e6, can = 0;
while (can < n) {
p1++;
p2--;
can += c[p1] + c[p2];
sol++;
}
printf("%d\n", sol);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool isv(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, x, ma = 1, mi = 1000000;
cin >> n;
for (long long int i = 0; i < n; i++) {
cin >> x;
if (x <= 500000)
ma = max(ma, x);
else
mi = min(mi, x);
}
long long int ans = max(ma - 1, 1000000 - mi);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bitset<1000009> bt;
int main() {
long long n, a, res = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a, bt.set(a);
for (long long i = 2, f = 1000000 - 1; i <= (1000000 >> 1); i++, f--)
if (bt[i] || bt[f]) res = i - 1;
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, lpos, rpos = 1000000;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int pos;
scanf("%d", &pos);
if (pos <= 500000)
lpos = max(lpos, pos);
else
rpos = min(rpos, pos);
}
printf("%d\n", max(lpos - 1, 1000000 - rpos));
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<long long> a(n);
for (auto &i : a) cin >> i;
long long ans = 1000000000000;
for (int i = 0; i <= n; ++i) {
long long t;
if (i == 0)
t = 1000000 - a[0];
else if (i == n)
t = a.back() - 1;
else
t = max(a[i - 1] - 1, 1000000 - a[i]);
ans = min(ans, t);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100010];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int maxn = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= 500000)
maxn = max(a[i] - 1, maxn);
else
maxn = max(1000000 - a[i], maxn);
}
cout << maxn << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, num, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num;
if (num <= 1e6 / 2)
ans = max(num - 1, ans);
else
ans = max(ans, 1000000 - num);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int t = 0, time;
int onerange = 1;
int large = 1000000;
for (int i = 0; i < x; i++) {
cin >> t;
if (t > 500000) {
if (t < large) {
large = t;
}
} else {
if (t > onerange) {
onerange = t;
}
}
}
if ((onerange - 1) > (1000000 - large)) {
cout << onerange - 1;
} else {
cout << 1000000 - large;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int main() {
int n;
while (cin >> n) {
int max1 = -1, max2 = -1;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a > INF / 2)
max2 = max(INF - a, max2);
else
max1 = max(a - 1, max1);
}
cout << max(max1, max2) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long read() {
long long x = 0;
bool q = 0;
char c = getchar();
while (!isdigit(c)) q |= (c == '-'), c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0', c = getchar();
return q ? -x : x;
}
void print(long long x, char q = '\n') {
if (x < 0) putchar('-'), x = -x;
if (x == 0) putchar('0');
stack<char> s;
s.push(q);
while (x > 0) s.push(x % 10 + '0'), x /= 10;
while (!s.empty()) putchar(s.top()), s.pop();
}
string read_s() {
string s;
char c = getchar();
while (c == ' ' || c == '\t' || c == '\n') c = getchar();
while (c != ' ' && c != '\t' && c != '\n') s += c, c = getchar();
return s;
}
void print_s(string s, char q = '\n') {
for (char c : s) putchar(c);
putchar(q);
}
char read_c() {
char c = getchar();
while (c == ' ' || c == '\t' || c == '\n') c = getchar();
return c;
}
bool isVowel(char q) {
if (q == 'a') return 1;
if (q == 'e') return 1;
if (q == 'i') return 1;
if (q == 'u') return 1;
if (q == 'o') return 1;
return 0;
}
int a[100002];
int main() {
int n = read();
for (int i = 0; i < n; i++) a[i] = read();
sort(a, a + n);
int ans = 1e9;
for (int i = 0; i < n - 1; i++)
ans = min(ans, max(a[i] - 1, 1000000 - a[i + 1]));
ans = min(ans, a[n - 1] - 1);
ans = min(ans, 1000000 - a[0]);
print(ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a, answer;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
answer = max(answer, min(a - 1, 1000000 - a));
}
cout << answer;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
a[0] = 1, a[n + 1] = 1000000;
int ans = 1e9;
for (int i = 0; i <= n; ++i) {
ans = min(ans, max(1000000 - a[i + 1], a[i] - 1));
}
ans = min(ans, 1000000 - a[1]);
ans = min(ans, a[n] - 1);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string vowels = "aeouiy";
const int N = 100100, R = 1000000;
int arr[N], dis1[N], dis2[N];
int main() {
int n, p1 = 1, p2 = R;
scanf("%d", &n);
long long ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
if (arr[i] <= R / 2) ans1 += abs(p1 - arr[i]), p1 = arr[i];
}
for (int i = n - 1; i >= 0; i--) {
if (arr[i] > R / 2) ans2 += abs(p2 - arr[i]), p2 = arr[i];
}
printf("%lld", max(ans1, ans2));
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n, val, mx = -1, L = 1e6;
cin >> n;
while (n--) {
cin >> val;
mx = max(min(val - 1, L - val), mx);
}
cout << mx << "\n";
return 0;
}
|
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
const long long INF = 1LL << 60;
const double PI = acos(-1);
using ll = long long;
using P = array<ll, 2>;
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
for (ll j = (0); j < (ll)(v.size()); ++j) i >> v[j];
return i;
}
template <typename T>
string join(vector<T>& v) {
stringstream s;
for (ll i = (0); i < (ll)(v.size()); ++i) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
if (v.size()) o << join(v);
return o;
}
template <typename T>
string join(vector<vector<T>>& vv) {
string s = "\n";
for (ll i = (0); i < (ll)(vv.size()); ++i) s += join(vv[i]) + "\n";
return s;
}
template <typename T>
ostream& operator<<(ostream& o, vector<vector<T>>& vv) {
if (vv.size()) o << join(vv);
return o;
}
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& v) {
return i >> v.first >> v.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, pair<T1, T2>& v) {
return o << "(" << v.first << "," << v.second << ")";
}
template <typename T>
istream& operator>>(istream& i, array<T, 2>& v) {
i >> v[0] >> v[1];
return i;
}
template <typename T>
ostream& operator<<(ostream& o, array<T, 2>& v) {
return o << "(" << v[0] << "," << v[1] << ")";
return o;
}
int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};
void init_init_init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout << fixed << setprecision(10);
}
template <class T>
T up(T a, T b) {
assert(b);
return (a + b - 1) / b;
}
template <typename... A>
bool eq(A const&... a) {
auto t = {a...};
assert(t.size());
auto tar = *t.begin();
for (const auto& e : t)
if (tar != e) return false;
return true;
}
template <class T>
bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmax(T& a, initializer_list<T> l) {
return chmax(a, max(l));
}
template <class T>
bool chmin(T& a, initializer_list<T> l) {
return chmin(a, min(l));
}
int main(int argc, char** argv) {
init_init_init();
ll N;
cin >> N;
vector<ll> A(N);
cin >> A;
ll res{INF};
chmin(res, 1000000 - A[0]);
chmin(res, A[N - 1] - 1);
for (ll i = 0; i < N - 1; ++i) {
chmin(res, max(A[i] - 1, 1000000 - A[i + 1]));
}
std::cout << res << std::endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, p = 0;
cin >> n;
vector<long long int> v;
for (int i = 0; i < n; i++) {
long long int a;
cin >> a;
if (a <= 500000)
p = max(p, a - 1);
else
p = max(p, 1000000 - a);
}
cout << p;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a[100500], mx = -999, total, cnt, id1 = 1, id2 = 1000000;
int main() {
cin >> n;
while (n--) {
int x;
cin >> x;
total = max(total, min(x - 1, 1000000 - x));
}
cout << total;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
int curr_len = 0;
int l = 0, r = a.size() - 1;
while (l <= r) {
if (a[l] - 1 < int(1e6) - a[r]) {
curr_len = a[l] - 1;
++l;
} else {
curr_len = int(1e6) - a[r];
--r;
}
}
cout << curr_len;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
ans = max(ans, min(x - 1, 1000000 - x));
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
double pi = 3.1415926535898;
string ys = "YES\n";
string no = "NO\n";
const double EPS = 1e-6;
const int inf = 1 << 20;
const long long M = 1e9 + 7;
int n, x;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
cin >> n;
int mxx = 0;
for (int i = 1; i <= int(n); ++i) {
cin >> x;
mxx = max(mxx, min(x - 1, 1000000 - x));
}
cout << mxx;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int time = 0;
int n;
cin >> n;
int value;
for (int i = 0; i < n; i++) {
cin >> value;
time = max(time, min(value - 1, 1000000 - value));
}
cout << time << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, res = 1e6 - 1;
int arr[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
arr[n] = 1e6;
res = 1000000 - arr[0];
for (int i = 0; i < n; ++i) {
res = min(res, max(arr[i] - 1, 1000000 - arr[i + 1]));
}
cout << res << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
int ma = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
ma = max(ma, min(a - 1, 1000000 - a));
}
cout << ma << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000001], n, i, t, w, l, r;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
t = 1;
w = n;
l = 1;
r = 1000000;
for (i = 1; i <= 1000000; i++) {
l++;
r--;
if (a[t] == l) t++;
if (a[w] == r) w--;
if (t > w) break;
}
printf("%d\n", i);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, ans = 0;
scanf("%d", &a);
for (int i = 0; i < a; i++) {
int temp;
cin >> temp;
ans = max(ans, min(temp - 1, 1000000 - temp));
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void A7med_S3d() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool isprime(long long n) {
if (n == 2) return true;
if (n < 2 || n % 2 == 0) return false;
for (long long i = 3; i * i <= n; i += 2)
if (n % i == 0) return false;
return true;
}
long long fact(short n) {
long long sum = 1;
if (n == 1) return sum;
for (int i = 2; i <= n; i++) sum *= i;
return sum;
}
int main() {
A7med_S3d();
int x;
cin >> x;
int a, ans = 0, mx = 0;
for (int i = 0; i < x; i++) {
cin >> a;
if (a - 1 <= 1000000 - a)
ans = a - 1;
else
ans = 1000000 - a;
mx = max(mx, ans);
}
cout << mx << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 100000 + 5;
int n;
int a[Nmax];
int main() {
cin >> n;
int t = 0;
for (int i = 1; i <= n; ++i) cin >> a[i];
int ii = 1, jj = n, poz1 = 1, poz2 = 1000000;
while (ii <= jj) {
if (abs(poz1 - a[ii]) < abs(poz2 - a[jj]))
t += abs(poz1 - a[ii]), poz2 -= abs(poz1 - a[ii]), poz1 = a[ii], ii++;
else
t += abs(poz2 - a[jj]), poz1 += abs(poz2 - a[jj]), poz2 = a[jj], jj--;
}
cout << t;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned n;
cin >> n;
unsigned i, a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
unsigned c = 0, t = 0;
for (i = 0; i < n; i++) {
if (a[i] <= 1000000 / 2) {
c = a[i] - 1;
} else {
t = 1000000 - a[i];
break;
}
}
cout << max(c, t);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ans = 0, start = 1, end = 1000000, maxi, temp = 0;
cin >> n;
int arr[n + 1];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
int ans1 = abs(arr[i] - start);
int ans2 = abs(end - arr[i]);
maxi = min(ans1, ans2);
if (maxi > temp) temp = maxi;
}
cout << temp << endl;
}
|
#include <bits/stdc++.h>
const bool DEBUG = false;
using namespace std;
const long long maxn = 3e5 + 5 + 1;
const long long INF = 4e18;
const long long M = 1e9 + 7;
const int lg = 21;
#pragma GCC Optimize("Ofast")
int n, a[maxn], mi = 1e6, ma;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > 1e6 / 2)
mi = min(mi, a[i]);
else
ma = max(ma, a[i]);
}
cout << max(ma - 1, 1000000 - mi);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.