text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
const int N = (1e3) + 7, K = N * 2;
int n, k, p;
int a[N], b[K];
int res = 2e9, Max;
void _input() {
cin >> n >> k >> p;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= k; ++i) cin >> b[i];
}
void _solve() {
sort(a + 1, a + n + 1);
sort(b + 1, b + k + 1);
for (int i = 1; i <= k - n + 1; ++i) {
Max = 0;
for (int j = 1; j <= n; ++j)
Max = max(Max, abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p));
res = min(res, Max);
}
}
void _output() { cout << res << '\n'; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
_input();
_solve();
_output();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using dd = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
ll INFLL = (ll)2e18, MOD = 1e9 + 7;
const int INF = 0x6f6f6f6f;
vector<vector<ll>> adj;
vector<int> vis;
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
inline ll mexp(ll x, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1) res = (res * x) % m;
n >>= 1;
x = ((x % m) * (x % m)) % m;
}
return res;
}
inline bool ispow2(ll x) { return x && (!(x & (x - 1))); }
inline ll gcd(ll x, ll y) {
pll p{x, y};
while (p.second) p = {p.second, p.first % p.second};
return p.first;
}
int main(void) {
cout << fixed;
cerr << fixed;
cout << setprecision(10);
cerr << setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());
ll n, k, p;
cin >> n >> k >> p;
vector<int> per(n), pos(k);
for (int i = 0; i < n; ++i) cin >> per[i];
for (int i = 0; i < k; ++i) cin >> pos[i];
ll ans = INFLL;
sort(pos.begin(), pos.end());
sort(per.begin(), per.end());
for (int i = 0; i <= k - n; ++i) {
ll temp = 0;
for (int j = 0; j < n; ++j) {
temp = max(temp, abs(pos[i + j] - per[j]) + abs(p - pos[i + j]));
}
ans = min(ans, temp);
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1123;
const long long INF = 1123456789123456789;
int n, m, opos;
int a[N], b[2 * N];
int main() {
scanf("%d%d%d", &n, &m, &opos);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
sort(b + 1, b + m + 1);
sort(a + 1, a + n + 1);
long long wyn = INF;
for (int i = 1; i <= (m - n + 1); ++i) {
long long cur = 0;
for (int j = 1; j <= n; ++j) {
cur = max(cur,
(long long)abs(b[i + j - 1] - a[j]) + abs(b[i + j - 1] - opos));
}
wyn = min(wyn, cur);
}
printf("%lld", wyn);
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
long long a[2000];
long long b[2001];
long long dp[1003][2004];
long long cnt = 0;
long long solve(long long index1, long long index2) {
if (index1 >= n) {
return dp[index1][index2] = 0;
}
if (index2 >= k) {
return dp[index1][index2] = LONG_LONG_MAX;
}
if (dp[index1][index2] != -1) {
return dp[index1][index2];
}
cnt++;
if (cnt > 10000000) {
cout << cnt << "\n";
exit(0);
}
long long ans = LONG_LONG_MAX;
ans = min(max(solve(index1 + 1, index2 + 1),
abs(a[index1] - b[index2]) + abs(b[index2] - p)),
solve(index1, index2 + 1));
return dp[index1][index2] = ans;
}
int main() {
scanf("%I64d %I64d %I64d", &n, &k, &p);
for (long long i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
for (long long i = 0; i < k; i++) {
scanf("%I64d", &b[i]);
}
sort(a, a + n);
sort(b, b + k);
memset(dp, -1, sizeof dp);
cout << solve(0, 0);
}
|
#include <bits/stdc++.h>
using namespace std;
const bool ready = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
return true;
}();
const double PI = acos(-1);
using ll = long long;
using pii = pair<ll, ll>;
using pdd = pair<double, double>;
using vd = vector<double>;
using vb = vector<bool>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
void solve() {
ll n;
cin >> n;
;
ll k;
cin >> k;
;
ll p;
cin >> p;
;
set<ll> pers;
for (ll i = 0; i < n; i++) {
ll aux;
cin >> aux;
;
pers.insert(aux);
}
set<ll> keys;
for (ll i = 0; i < k; i++) {
ll aux;
cin >> aux;
;
keys.insert(aux);
}
ll l = -1;
ll r = 1e10;
while (l + 1 < r) {
ll t = (l + r) / 2;
set<ll> lpers = pers;
set<ll> lkeys = keys;
bool imp = false;
while (lpers.size()) {
auto it1 = lpers.begin();
auto it2 = lpers.rbegin();
ll lp;
if (abs(*it1 - p) >= abs(*it2 - p))
lp = *it1;
else
lp = *it2;
lpers.erase(lp);
if (abs(lp - p) > t) {
imp = true;
break;
}
if (lp >= p) {
ll d = lp - p;
ll mak = lp + (t - d) / 2;
auto it = lkeys.upper_bound(mak);
if (it != lkeys.begin()) {
it--;
}
if (abs(lp - *it) + abs(*it - p) > t) {
imp = true;
break;
}
lkeys.erase(*it);
} else {
ll d = p - lp;
ll mik = lp - (t - d) / 2;
auto it = lkeys.lower_bound(mik);
if (it == lkeys.end()) {
imp = true;
break;
}
if (abs(lp - *it) + abs(*it - p) > t) {
imp = true;
break;
}
lkeys.erase(*it);
}
}
if (imp)
l = t;
else
r = t;
}
cout << r << endl;
}
signed main() { solve(); }
|
#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 5;
const long long inf = 2000000000;
long long Abs(long long x) { return x > 0 ? x : -x; }
long long p[N], q[N], n, m, s, ans;
long long tim(int i, int j) { return Abs(p[i] - q[j]) + Abs(q[j] - s); }
bool check(long long x) {
for (int i = 1, j = 1; i <= n; i++, j++) {
while (tim(i, j) > x && j <= m) j++;
if (j > m) return false;
}
return true;
}
int main() {
scanf("%d%d%d", &n, &m, &s);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
for (int i = 1; i <= m; i++) scanf("%d", &q[i]);
sort(p + 1, p + n + 1);
sort(q + 1, q + m + 1);
long long l = 0, r = inf;
while (l <= r) {
long long mid = l + r >> 1;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9 + 7;
long long n, k, a[MAXN], b[MAXN], p, mx, mn;
long long sum(long long a, long long b) { return (a + b) % MD; }
long long mu(long long a, long long b) { return (a * b) % MD; }
long long mon(long long a, long long b) { return (a - b + MD) % MD; }
int main() {
mn = 1e18;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> p;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= k; ++i) cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + k);
for (int i = 0; i <= k - n; ++i) {
mx = 0;
for (int j = 1; j <= n; ++j) {
mx = max(mx, abs(a[j] - b[i + j]) + abs(b[i + j] - p));
}
mn = min(mn, mx);
}
cout << mn;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k, p, i, j, l;
cin >> n >> k >> p;
long long arr[n];
long long brr[k];
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < k; i++) cin >> brr[i];
sort(arr, arr + n);
sort(brr, brr + k);
long long ans = 1e18;
for (i = 0; i < k; i++) {
if (i + n - 1 < k) {
long long mx = -1e18;
for (j = i; j <= i + n - 1; j++) {
long long d1 = abs(arr[j - i] - brr[j]);
long long d2 = abs(p - brr[j]);
mx = max(mx, d1 + d2);
}
ans = min(ans, mx);
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void Out(long long a) {
if (a < 0) putchar('-'), a = -a;
if (a >= 10) Out(a / 10);
putchar(a % 10 + '0');
}
const int N = 2005;
long long a[N], b[N];
long long dp[N][N];
int main() {
int n = read(), m = read(), p = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= m; i++) b[i] = read();
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i <= m; i++) dp[0][i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
dp[i][j] = min(dp[i][j - 1],
max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p)));
}
Out(dp[n][m]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int maxn = 2000 + 10;
int k[maxn], r[maxn];
int nk, nr, pos;
int dp[maxn][maxn];
int main() {
scanf("%d%d%d", &nr, &nk, &pos);
for (int i = 1; i <= nr; i++) scanf("%d", &r[i]);
for (int i = 1; i <= nk; i++) scanf("%d", &k[i]);
sort(r + 1, r + nr + 1);
sort(k + 1, k + 1 + nk);
for (int i = 0; i <= nr; i++) fill(dp[i], dp[i] + nr + 1, inf);
fill(dp[0], dp[0] + nk + 1, 0);
for (int i = 1; i <= nr; i++)
for (int j = i; j <= nk; j++) {
int d = abs(r[i] - k[j]) + abs(k[j] - pos);
dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1], d));
}
printf("%d\n", dp[nr][nk]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long person[1005];
long long key[2005];
int n, k;
long long p;
long long answer;
long long cal(int start) {
long long time = -1;
long long per, ke, office;
office = p;
for (int i = 0; i < n; i++) {
per = person[i];
ke = key[start + i];
time = max(time, abs(ke - per) + abs(office - ke));
}
return time;
}
int main() {
scanf("%d%d", &n, &k);
scanf("%lld", &p);
for (int i = 0; i < n; i++) scanf("%lld", &person[i]);
for (int i = 0; i < k; i++) scanf("%lld", &key[i]);
sort(person, person + n);
sort(key, key + k);
int left = 0, right = k - n;
for (int i = k - 1; i >= 0; i--) {
if (key[i] < p) {
left = i;
break;
}
}
for (int i = 0; i < k; i++) {
if (key[i] > p) {
right = i;
break;
}
}
if (left != 0) {
left = max(left - n, 0);
}
if (right != k - n) {
right = min(right, k - n);
}
for (int i = left; i <= right; i++) {
if (i == left)
answer = cal(i);
else
answer = min(answer, cal(i));
}
printf("%lld\n", answer);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const double eps = (1e-10);
long long n, k, p;
long long a[1005], b[2005];
bool check(long long x) {
long long j = 0;
for (int i = 0; i < (int)(n); ++i) {
if (j == k) return 0;
while (abs(b[j] - a[i]) + abs(b[j] - p) > x) {
++j;
if (j == k) return 0;
}
++j;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.precision(10);
cin >> n >> k >> p;
for (int i = 0; i < (int)(n); ++i) cin >> a[i];
for (int i = 0; i < (int)(k); ++i) cin >> b[i];
sort(a, a + n);
sort(b, b + k);
long long st = 0, en = 1e18;
while (en > st) {
long long m = (en + st) / 2;
if (check(m))
en = m;
else
st = m + 1;
}
cout << st, cout << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int N, K, A[maxn], B[maxn];
long long f[maxn][maxn], P;
inline int gi() {
char ch;
int ret = 0, f = 1;
do ch = getchar();
while (!(ch >= '0' && ch <= '9') && ch != '-');
if (ch == '-') f = -1, ch = getchar();
do ret = ret * 10 + ch - '0', ch = getchar();
while (ch >= '0' && ch <= '9');
return ret * f;
}
int main() {
N = gi();
K = gi();
P = gi();
for (int i = 1; i <= N; ++i) A[i] = gi();
for (int i = 1; i <= K; ++i) B[i] = gi();
sort(A + 1, A + N + 1);
sort(B + 1, B + K + 1);
f[0][0] = 0;
for (int i = 1; i <= N; ++i) {
f[i][0] = 1LL << 60;
for (int j = 1; j <= K; ++j) {
f[i][j] = f[i][j - 1];
f[i][j] = min(f[i][j], max(f[i - 1][j - 1],
1LL * abs(A[i] - B[j]) + 1LL * abs(P - B[j])));
}
}
cout << f[N][K] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 1;
int n, A[N], B[N], k, f;
long long sol;
int main() {
scanf("%d %d %d", &n, &k, &f);
for (int i = 1; i <= n; i++) {
scanf("%d", &A[i]);
}
for (int i = 1; i <= k; i++) {
scanf("%d", &B[i]);
}
sort(A + 1, A + n + 1);
sort(B + 1, B + k + 1);
long long sol = 1e18;
for (int i = 1; i <= k - n + 1; i++) {
long long t = 0;
for (int j = i; j <= i + n - 1; j++) {
int x = abs(B[j] - A[j - i + 1]);
int cur = B[j];
int a = abs(f - cur);
t = max((long long)x + (long long)a, t);
}
sol = min(t, sol);
}
printf("%I64d", sol);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int A[1001];
int B[2001];
int N, K, P;
bool is_ok(int t) {
int now = 1;
for (int i = 1; i <= N; i++) {
while (abs(A[i] - B[now]) + abs(B[now] - P) > t && now <= K) now++;
if (now > K) return false;
now++;
}
return true;
}
int main() {
scanf("%d %d %d", &N, &K, &P);
for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
sort(&A[1], &A[N] + 1);
for (int i = 1; i <= K; i++) scanf("%d", &B[i]);
sort(&B[1], &B[K] + 1);
int lbound = max(P - A[1], A[N] - P), rbound = 2e9;
while (rbound - lbound > 5) {
int mid = ((long long)lbound + rbound) / 2;
if (is_ok(mid))
rbound = mid;
else
lbound = mid + 1;
}
for (int i = lbound; i <= rbound; i++)
if (is_ok(i)) {
printf("%d", i);
return 0;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
const long long INF = 40000000000000000LL;
void solve(int tc) {
long long n, k, p;
cin >> n >> k >> p;
vector<long long> a(n), b(k);
vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, INF));
dp[0][0] = 0;
for (long long &i : a) cin >> i;
for (long long &i : b) cin >> i;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for (int i = 0; i <= n; i++) {
for (int j = 0; j < k; j++) {
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
if (i < n)
dp[i + 1][j + 1] = min(dp[i + 1][j + 1],
max(dp[i][j], abs(a[i] - b[j]) + abs(b[j] - p)));
}
}
for (int i = 0; i <= n; i++) {
;
cout << endl;
}
cout << dp[n][k] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << setprecision(15) << fixed;
int tc = 1;
for (int t = 1; t <= tc; t++) solve(t);
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k, p, l, r, mid, a[1005], b[2005];
inline char chck(int x) {
for (int i = 1, j = 0; i <= n; i++) {
while (j <= k) {
j++;
if (abs(a[i] - b[j]) + abs(b[j] - p) <= x) break;
}
if (j > k) return 0;
}
return 1;
}
int main() {
scanf("%d%d%d", &n, &k, &p), l = 0, r = 2e9;
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= k; i++) scanf("%d", b + i);
sort(a + 1, a + n + 1), sort(b + 1, b + k + 1);
while (l < r) {
mid = ((long long)l + r) >> 1;
if (chck(mid))
r = mid;
else
l = mid + 1;
}
return printf("%d\n", l), 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int a[3000];
int b[3000];
int dist(int a, int b) {
if (a > b)
return a - b;
else
return b - a;
}
const char people = 1;
const char keystart = 0;
struct node {
int pos;
char type;
int end;
bool operator<(const node& x) const {
if (pos != x.pos) return pos < x.pos;
return type < x.type;
}
};
bool test(int dis) {
multiset<node> s;
multiset<int> end;
for (int i = 0; i < k; i++) {
int remain = dis - dist(b[i], p);
s.insert({b[i] - remain, keystart, b[i] + remain});
}
for (int i = 0; i < n; i++) {
s.insert({a[i], people, 0});
}
for (const auto& x : s) {
auto pos = x.pos;
while (end.size() && *end.begin() < pos) {
end.erase(end.begin());
}
if (x.type == keystart) {
end.insert(x.end);
} else {
if (end.empty()) return false;
end.erase(end.begin());
}
}
return true;
}
int main() {
scanf("%d%d%d", &n, &k, &p);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
for (int i = 0; i < k; i++) {
scanf("%d", b + i);
}
long long l = 0, r = 2e9 + 1;
while (l != r) {
long long mid = (l + r) / 2;
if (test(mid)) {
r = mid;
} else {
if (l == mid) break;
l = mid;
}
}
printf("%d\n", r);
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, k, p;
long long dp[N][N];
int a[N], b[N];
long long solve(int i, int j) {
if (i == n) return 0;
if (j == k) return 1e18;
if (dp[i][j] != -1) return dp[i][j];
dp[i][j] = 1e18;
long long dis = p - b[j];
long long dis2 = a[i] - b[j];
if (dis < 0) dis *= -1;
if (dis2 < 0) dis2 *= -1;
long long cur = dis + dis2;
return dp[i][j] = min(max(solve(i + 1, j + 1), cur), solve(i, j + 1));
}
int main() {
memset(dp, -1, sizeof(dp));
scanf("%d%d%d", &n, &k, &p);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < k; i++) scanf("%d", &b[i]);
sort(a, a + n);
sort(b, b + k);
cout << solve(0, 0) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> people;
vector<pair<int, int>> keys;
int office, n, k;
bool check(int a) {
int p = 0, key = 0, cnt = 0;
while (p < n && key < k) {
if (abs(people[p] - keys[key].first) + keys[key].second <= a) {
key++;
cnt++;
p++;
} else
key++;
}
return cnt == n;
}
int main() {
cin >> n >> k >> office;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
people.push_back(x);
}
for (int i = 0, x; i < k; ++i) {
cin >> x;
keys.push_back(make_pair(x, abs(x - office)));
}
sort(people.begin(), people.end());
sort(keys.begin(), keys.end());
long long beg = 0, end = 5000000000;
while (end - beg > 1) {
int mid = (beg + end) / 2;
if (check(mid))
end = mid;
else
beg = mid;
}
if (check(beg))
cout << beg;
else
cout << end;
cin >> beg;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, p;
scanf("%d%d%d", &n, &k, &p);
vector<int> pos(n), s(k);
for (int i = 0; i < n; i++) {
scanf("%d", &pos[i]);
}
for (int i = 0; i < k; i++) {
scanf("%d", &s[i]);
}
sort(pos.begin(), pos.end());
sort(s.begin(), s.end());
long long ans = 1e18;
for (int i = 0; i <= k - n; i++) {
long long mx = 0;
for (int j = 0; j < n; j++) {
long long time1 = abs(pos[j] - s[i + j]);
long long time2 = abs(s[i + j] - p);
mx = max(mx, (long long)time1 + time2);
}
ans = min(mx, ans);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long posp[2005], posk[2005], n, m, ans, off;
long long samay[2005][2005];
bool check(long long t) {
long long pers = 1;
for (long long i = 1; i <= m; i++) {
if (samay[pers][i] <= t) pers++;
if (pers > n) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> off;
for (long long i = 1; i <= n; i++) cin >> posp[i];
for (long long i = 1; i <= m; i++) cin >> posk[i];
sort(posp + 1, posp + n + 1);
sort(posk + 1, posk + m + 1);
for (long long i = 1; i <= n; i++)
for (long long j = 1; j <= m; j++)
samay[i][j] = abs(posp[i] - posk[j]) + abs(posk[j] - off);
long long lo = 0, hi = 10000000000000;
while (lo <= hi) {
long long mid = (lo + hi) / 2;
bool f = check(mid);
if (f) {
ans = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void Out(long long a) {
if (a < 0) putchar('-'), a = -a;
if (a >= 10) Out(a / 10);
putchar(a % 10 + '0');
}
const int N = 1005;
long long a[N], b[N << 1];
long long dp[N][N << 1];
int n, m, p;
long long cacu(long long a, long long b) {
if (b <= a && a <= p)
return abs(p - a) + abs(a - b) * 2;
else if (a <= b && b <= p)
return abs(p - a);
else
return abs(a - b) + abs(p - b);
}
int main() {
n = read();
m = read();
p = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= m; i++) b[i] = read();
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i <= m; i++) dp[0][i] = 0;
for (int i = 1; i <= n; i++)
for (int j = i; j <= m; j++) {
dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1], cacu(a[i], b[j])));
}
Out(dp[n][m]);
puts("");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int arr[1005], arr2[2005], taken[2005];
bool check(int mid) {
memset(taken, 0, sizeof(taken));
for (int i = 0; i < n; ++i) {
int idx = -1, idx2 = -1;
for (int j = 0; j < k; ++j) {
if (taken[j] == 0 && arr[i] >= arr2[j] &&
((arr[i] - arr2[j] + abs(p - arr2[j])) <= mid)) {
idx = j;
break;
}
}
for (int j = 0; j < k; ++j) {
if (taken[j] == 0 && arr[i] < arr2[j] &&
arr2[j] - arr[i] + abs(p - arr2[j]) <= mid) {
idx2 = j;
break;
}
}
if (idx == -1 && idx2 == -1) return 0;
if (idx != -1)
taken[idx] = 1;
else
taken[idx2] = 1;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> p;
for (int i = 0; i < n; ++i) cin >> arr[i];
for (int i = 0; i < k; ++i) cin >> arr2[i];
sort(arr, arr + n);
sort(arr2, arr2 + k);
long long l = 0, r = 2e9, ans = 2e9;
while (l <= r) {
long long mid = (l + r) >> 1;
if (check(mid))
r = mid - 1, ans = min(ans, mid);
else
l = mid + 1;
}
return cout << ans << "\n", 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int N = 2e3 + 5;
int a[N], b[N];
long long dp[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, p;
cin >> n >> m >> p;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) cin >> b[i];
sort(a + 1, a + n + 1), sort(b + 1, b + m + 1);
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= m; ++j) {
dp[i][j] =
max(dp[i - 1][j - 1], (long long)(abs(a[i] - b[j])) + abs(b[j] - p));
if (j - 1 >= i) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
}
long long ans = INF;
for (int j = n; j <= m; ++j) ans = min(ans, dp[n][j]);
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int n, k, p;
int dp[maxn][maxn];
int a[maxn], key[maxn];
int main() {
scanf("%d %d %d", &n, &k, &p);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= k; ++i) scanf("%d", &key[i]);
sort(a + 1, a + 1 + n);
sort(key + 1, key + 1 + k);
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= n; ++j) {
if (i == j)
dp[i][j] = max(dp[i - 1][j - 1], abs(a[j] - key[i]) + abs(p - key[i]));
else
dp[i][j] = min(dp[i - 1][j], max(dp[i - 1][j - 1],
abs(a[j] - key[i]) + abs(p - key[i])));
}
}
printf("%d", dp[k][n]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1001, K = 2001;
const long long INF = 1e18;
int n, k, p, a[N], b[K];
long long dp[N][K];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> p;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= k; i++) cin >> b[i];
sort(a + 1, a + n + 1);
sort(b + 1, b + k + 1);
for (int i = 1; i <= n; i++) fill(dp[i], dp[i] + K, INF);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= k; j++) {
dp[i][j] = min(
max(dp[i - 1][j - 1], (long long)abs(a[i] - b[j]) + abs(b[j] - p)),
dp[i][j - 1]);
}
cout << dp[n][k];
}
|
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2000;
const int inf = 1 << 30;
int a[nmax + 1], b[nmax + 1];
int main() {
int n, m, p;
cin.sync_with_stdio(false);
cin >> n >> m >> p;
int ind1 = 0, ind2 = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
ind1 += (a[i] <= p);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= m; ++i) {
cin >> b[i];
ind2 += (b[i] <= p);
}
sort(b + 1, b + m + 1);
int ans = inf - 1 + inf;
for (int i = 1; i <= m - n + 1; ++i) {
int sol = 0;
for (int j = 1; j <= n; ++j) {
sol = max(sol, abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p));
}
ans = min(ans, sol);
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
long int of;
long long int dp[1001][2001];
long long int val[1001], pos[2001];
long long int fn(int ind, int ke) {
if (dp[ind][ke] != -1) return dp[ind][ke];
long long int opt1 = 0, opt2 = 0, temp = 0;
if (ind <= n) {
if (ind < n) opt1 = fn(ind + 1, ke + 1);
temp = max(val[ind] - pos[ke], pos[ke] - val[ind]) +
max(of - pos[ke], pos[ke] - of);
}
if ((k - ke) >= (n - ind + 1)) opt2 = fn(ind, ke + 1);
opt1 = max(opt1, temp);
if (opt1 == 0)
return dp[ind][ke] = opt2;
else if (opt2 == 0)
return dp[ind][ke] = opt1;
return dp[ind][ke] = min(opt1, opt2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k >> of;
for (int i = 1; i <= n; ++i) cin >> val[i];
sort(val + 1, val + 1 + n);
for (int i = 1; i <= k; ++i) cin >> pos[i];
sort(pos + 1, pos + 1 + k);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) dp[i][j] = -1;
}
cout << fn(1, 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[1234][2 * 1234];
long long N, K, P;
long long arr[1234];
long long brr[2 * 1234];
long long fun(long long idx1, long long idx2) {
if (idx2 <= K && idx1 == N) return 0;
if (idx2 >= K) return 1e18;
if (dp[idx1][idx2] != -1) return dp[idx1][idx2];
long long temp = max(abs(arr[idx1] - brr[idx2]) + abs(brr[idx2] - P),
fun(idx1 + 1, idx2 + 1));
temp = min(temp, fun(idx1, idx2 + 1));
return dp[idx1][idx2] = temp;
}
int main() {
cin >> N >> K >> P;
long long i, j;
for (i = 0; i < N; i++) cin >> arr[i];
for (i = 0; i < K; i++) cin >> brr[i];
sort(arr, arr + N);
sort(brr, brr + K);
memset(dp, -1, sizeof dp);
printf("%lld", fun(0, 0));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
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* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&) {
return *this;
}
};
using ll = long long;
using ld = long double;
constexpr int nax = 2005;
constexpr ll infty = 1e14;
constexpr int mod = 1000 * 1000 * 1000 + 7;
int n, k;
ll p;
vector<ll> a, b;
ll dp[nax][nax];
bool juz[nax][nax];
ll Koszt(int x, int y) { return abs(a[x] - b[y]) + abs(b[y] - p); }
ll Dp(int x, int y);
ll Dp_(int x, int y) {
if (x == 0) return 0;
if (y == 0) return infty;
return min(Dp(x, y - 1), max(Dp(x - 1, y - 1), Koszt(x, y)));
}
ll Dp(int x, int y) {
if (juz[x][y]) return dp[x][y];
juz[x][y] = true;
return dp[x][y] = Dp_(x, y);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> p;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
}
for (int i = 0; i < k; i++) {
int x;
cin >> x;
b.push_back(x);
}
a.push_back(0);
b.push_back(0);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
cout << Dp(n, k) << endl;
return 0;
}
|
#include <bits/stdc++.h>
const int N = 2010;
long long n, k, p;
long long a[N], b[N], left[N], right[N];
std::pair<long long, long long> pp[N];
std::priority_queue<int> pq;
bool check(long long mid) {
memset(left, 0x7f, sizeof(left));
memset(right, 0, sizeof(right));
for (long long i = 0; i < n; ++i) {
for (long long j = 0; j < k; ++j) {
if (std::abs(a[i] - b[j]) + std::abs(b[j] - p) <= mid) {
left[i] = std::min(left[i], j);
right[i] = std::max(right[i], j);
}
}
}
for (long long i = 0; i < n; ++i) {
if (left[i] > right[i]) {
return false;
}
pp[i] = {left[i], right[i]};
}
std::sort(pp, pp + n);
while (!pq.empty()) {
pq.pop();
}
for (int i = 0, j = 0; i < k; ++i) {
while (j < n && pp[j].first == i) {
pq.push(-pp[j++].second);
}
if (!pq.empty()) {
if (-pq.top() < i) {
return false;
}
pq.pop();
}
}
return pq.empty();
}
int main() {
scanf("%I64d%I64d%I64d", &n, &k, &p);
for (long long i = 0; i < n; ++i) {
scanf("%I64d", &a[i]);
}
std::sort(a, a + n);
for (long long j = 0; j < k; ++j) {
scanf("%I64d", &b[j]);
}
std::sort(b, b + k);
long long left = 0, right = 1e10;
while (left < right) {
long long mid = left + right >> 1;
if (check(mid)) {
right = mid;
} else {
left = mid + 1;
}
}
return printf("%I64d\n", left), 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int man[1005];
int key[2005];
int dis[1005][2005];
int dp[1005][2005];
inline int cmp(int a, int b) { return a < b; }
int minn(int a, int b) {
if (a >= b) return b;
return a;
}
int maxx(int a, int b) {
if (a >= b) return a;
return b;
}
int main() {
cin >> n >> k >> p;
for (register int i = 1; i <= n; i++) {
cin >> man[i];
}
for (register int i = 1; i <= k; i++) {
cin >> key[i];
}
sort(man + 1, man + n + 1, cmp);
sort(key + 1, key + k + 1, cmp);
for (register int i = 0; i <= n; i++) {
for (register int j = 0; j <= k; j++) {
dis[i][j] = fabs(man[i] - key[j]) + fabs(key[j] - p);
dp[i][j] = 2147483647;
}
}
for (register int i = 0; i <= k; i++) {
dp[0][i] = 0;
}
for (register int i = 1; i <= n; i++) {
for (register int j = 1; j <= k; j++) {
dp[i][j] = minn(dp[i][j - 1], maxx(dp[i - 1][j - 1], dis[i][j]));
}
}
int ans = 2147483647;
for (register int i = n; i <= k; i++) {
ans = min(ans, dp[n][i]);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, M, P, a[2017], b[2017];
int modul(int x) {
if (x < 0) return -x;
return x;
}
bool ok(int lim) {
int j = 1;
for (int i = 1; i <= N; i++) {
while (modul(a[i] - b[j]) + modul(b[j] - P) > lim && j <= M) j++;
if (j > M) return 0;
j++;
}
return 1;
}
int main() {
scanf("%d %d %d", &N, &M, &P);
for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
for (int i = 1; i <= M; i++) scanf("%d", &b[i]);
sort(a + 1, a + N + 1);
sort(b + 1, b + M + 1);
int p = 0, u = 2e9, mij, ras = -1;
while (p <= u) {
mij = p + (u - p) / 2;
if (ok(mij))
ras = mij, u = mij - 1;
else
p = mij + 1;
}
printf("%d\n", ras);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
int n, k, p, a[2000], b[2000];
bool ok(long long mid) {
int co = 0;
for (int i = 0; i < n; i++) {
while (abs(a[i] - b[co]) + abs(b[co] - p) > mid && co < k) co++;
if (co == k) return 0;
co++;
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> p;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < k; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + k);
long long mn = 0, mx = 2000000000;
while (mn < mx) {
long long mid = (mn + mx) / 2;
if (ok(mid))
mx = mid;
else
mn = mid + 1;
}
cout << mn;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int A[N], pos[N];
int n, k, p, ans;
int abs(int k) { return max(k, -k); }
int main() {
scanf("%d%d%d", &n, &k, &p);
for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
for (int i = 1; i <= k; i++) scanf("%d", &pos[i]);
sort(A + 1, A + n + 1);
sort(pos + 1, pos + k + 1);
ans = (int)(2 * 1e9);
for (int i = 0; i <= k - n; i++) {
int cur = 0;
for (int j = 1; j <= n; j++)
cur = max(cur, abs(A[j] - pos[i + j]) + abs(p - pos[i + j]));
ans = min(ans, cur);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
const int MAXN = 1005;
const int MAXK = 2005;
using namespace std;
long long p[MAXN], d[MAXK];
int n, k;
long long pos;
bool check(long long x) {
int id = 1;
int cnt = 0;
for (int i = 1; i <= k && id <= n; i++) {
long long tmp = abs(p[id] - d[i]) + abs(pos - d[i]);
if (tmp <= x) {
id++;
cnt++;
}
}
if (cnt == n) {
return true;
} else {
return false;
}
}
int main() {
scanf("%d %d %lld", &n, &k, &pos);
for (int i = 1; i <= n; i++) {
scanf("%lld", &p[i]);
}
for (int i = 1; i <= k; i++) {
scanf("%lld", &d[i]);
}
sort(p + 1, p + 1 + n);
sort(d + 1, d + 1 + k);
long long low = 0, up = 1e18, ans;
while (low <= up) {
long long mid = (low + up) >> 1;
if (check(mid)) {
ans = mid;
up = mid - 1;
} else {
low = mid + 1;
}
}
printf("%I64d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[200005], b[200006];
int n, k, p;
bool check(long long mid) {
int sum = 0;
int c = 0;
for (int i = 0; i < n; i++) {
for (int j = c; j < k; j++) {
if (abs(a[i] - b[j]) + abs(b[j] - p) <= mid) {
c = j + 1;
sum++;
break;
}
}
}
return sum == n;
}
int main() {
cin >> n >> k >> p;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < k; i++) scanf("%d", &b[i]);
sort(a, a + n);
sort(b, b + k);
long long L = 0, R = 1e15, mid, ans = -1;
while (L <= R) {
mid = (L + R) / 2;
if (check(mid)) {
ans = mid;
R = mid - 1;
} else
L = mid + 1;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename t1>
void print(vector<t1>& arr) {
for (t1 x : arr) cout << x << " ";
cout << "\n";
}
template <typename t1>
void print(vector<vector<t1>>& arr) {
for (vector<t1> vec : arr) {
for (t1 x : vec) cout << x << " ";
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, p;
cin >> n >> k >> p;
vector<long> a(n + 1), b(k + 1);
a[0] = 0;
b[0] = 0;
for (int i = 0; i < n; i++) {
cin >> a[i + 1];
}
sort(a.begin(), a.end());
for (int i = 0; i < k; i++) {
cin >> b[i + 1];
}
sort(b.begin(), b.end());
vector<vector<long>> dp(k + 1, vector<long>(n + 1, LONG_MAX));
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= n; j++) {
if ((i == 0 && j == 0) || j == 0)
dp[i][j] = 0;
else if (i == 0)
continue;
else {
if (i > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j],
max(dp[i - 1][j - 1], abs(a[j] - b[i]) + abs(b[i] - p)));
}
}
}
cout << dp[k][n] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
long long dp[2010][2010], a[2010], b[2010];
int main() {
int n, k, p;
scanf("%d%d%d", &n, &k, &p);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= k; i++) scanf("%d", &b[i]);
sort(a + 1, a + n + 1);
sort(b + 1, b + k + 1);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= k; j++) dp[i][j] = INFLL;
for (int i = 0; i <= k; i++) dp[0][i] = 0;
for (int i = 1; i <= n; i++)
for (int j = i; j <= k; j++)
dp[i][j] = min(dp[i][j - 1],
max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p)));
printf("%I64d\n", dp[n][k]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, p;
cin >> n >> k >> p;
int a[n], b[k];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < k; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + k);
int ans = INT_MAX;
for (int i = 0; i < k - n + 1; i++) {
int cur = 0;
for (int j = 0; j < n; j++)
cur = max(cur, abs(a[j] - b[i + j]) + abs(b[i + j] - p));
ans = min(ans, cur);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 0x3f3f3f3f3f3f3f3f;
int64_t dp[1010][2010], a[1010], b[2010];
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(0);
int n, k, p;
cin >> n >> k >> p;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= k; i++) cin >> b[i];
sort(b + 1, b + k + 1);
memset(dp, INF, sizeof(dp));
for (int i = 0; i <= k; i++) dp[n][i] = 0;
for (int i = n; i > 0; i--) {
int64_t mn = INF;
for (int j = k; j > 0; j--) {
mn = min(mn, max(dp[i][j], abs(a[i] - b[j]) + abs(b[j] - p)));
dp[i - 1][j - 1] = mn;
}
}
cout << dp[0][0] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, k;
long long p, a[maxn], b[maxn << 1], dp[maxn][maxn << 1];
int main() {
scanf("%d %d %lld", &n, &k, &p);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
for (int i = 1; i <= k; i++) {
scanf("%lld", &b[i]);
}
sort(a + 1, a + n + 1), sort(b + 1, b + k + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (j == i) {
dp[i][j] = max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p));
} else {
dp[i][j] = min(dp[i][j - 1],
max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p)));
}
}
}
printf("%lld\n", dp[n][k]);
return 0;
}
|
#include <bits/stdc++.h>
const int MaxN = 2000;
using namespace std;
long long a[MaxN + 5], b[MaxN + 5];
long long n, m, K;
bool check(int x) {
int now = 1;
for (int i = 1; i <= m; i++) {
if (abs(b[i] - a[now]) > x)
continue;
else if (abs(b[i] - a[now]) + abs(K - b[i]) <= x)
now++;
}
if (now > n) return true;
return false;
}
int main() {
while (~scanf("%lld%lld%lld", &n, &m, &K)) {
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i <= m; i++) scanf("%lld", &b[i]);
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
long long l = -1, r = 2e9 + 4;
while (l < r - 1) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid;
}
printf("%d\n", r);
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct RTC {};
const int maxn = 1010;
const int maxk = 2010;
vector<vector<int> > g;
bool mark[maxn + maxk];
int match[maxn + maxk];
bool dfs(int left) {
if (mark[left]) return false;
mark[left] = true;
for (int right : g[left])
if (match[right] == -1 || dfs(match[right])) {
match[right] = left;
match[left] = right;
return true;
}
return false;
}
int MCBM(int n, int k) {
fill(match, match + n + k, -1);
while (true) {
bool fnd = false;
fill(mark, mark + n + k, false);
for (int i = 0; i < (n); i++)
if (match[i] == -1 && !mark[i]) fnd |= dfs(i);
if (!fnd) break;
}
int ans = 0;
for (int i = 0; i < (n); i++)
if (match[i] != -1) ans++;
return ans;
}
vector<long long> personas, llaves;
long long p;
bool check(int n, int k, long long mid) {
g = vector<vector<int> >(n);
for (int i = 0; i < (n); i++)
for (int j = 0; j < (k); j++) {
long long costo = abs(llaves[j] - personas[i]) + abs(llaves[j] - p);
if (costo <= mid) g[i].push_back(n + j);
}
return MCBM(n, k) == n;
}
int main() {
int n, k;
scanf("%d %d %lld", &n, &k, &p);
personas = vector<long long>(n);
llaves = vector<long long>(k);
for (int i = 0; i < (n); i++) scanf("%lld", &personas[i]);
for (int i = 0; i < (k); i++) scanf("%lld", &llaves[i]);
if (check(n, k, 0)) {
puts("0");
return 0;
}
long long int a = 0, b = 200000000010LL;
while (b - a > 1) {
long long int mid = (a + b) >> 1LL;
if (check(n, k, mid))
b = mid;
else
a = mid;
}
printf("%lld\n", b);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int per[5000], key[5000];
long long dp[5000][5000];
int n, m, l;
long long solve(int p, int k) {
if (p == n) return 0;
if (k == m) return 10000000000100;
if (dp[p][k] != -1) return dp[p][k];
return dp[p][k] = min(solve(p, k + 1),
max((long long)abs(l - key[k]) + abs(per[p] - key[k]),
solve(p + 1, k + 1)));
}
int main() {
scanf("%d", &n);
scanf("%d", &m);
scanf("%d", &l);
for (int i = 0; i < n; ++i) scanf("%d", &per[i]);
for (int i = 0; i < m; ++i) scanf("%d", &key[i]);
memset(dp, -1, sizeof(dp));
sort(per, per + n);
sort(key, key + m);
long long ans = solve(0, 0);
printf("%lld", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[1005];
long long key[2005];
int n, k, p;
bool check(long long time) {
int pos = 0;
for (int i = 1; i <= n; i++) {
while (pos <= k) {
++pos;
if (1LL * abs(a[i] - key[pos]) + abs(key[pos] - p) <= time) break;
}
if (pos > k) return false;
}
return true;
}
int main() {
while (cin >> n >> k >> p) {
for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
for (int i = 1; i <= k; ++i) scanf("%lld", key + i);
sort(a + 1, a + 1 + n);
sort(key + 1, key + 1 + k);
long long l = 0, r = 2e9, mid;
long long ans = 0;
while (l < r) {
mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%lld\n", l);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
class Printer {
public:
static void print(vector<int> v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << "\n";
}
static void print(int v[], int size) {
for (int i = 0; i < size; i++) {
cout << v[i] << " ";
}
cout << "\n";
}
static void print(vector<vector<int> > v) {
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v[i].size(); j++) {
cout << v[i][j] << " ";
}
cout << "\n";
}
cout << "\n";
}
};
int n, k, p, t;
vector<int> people;
vector<int> keys;
int main() {
scanf("%d %d %d", &n, &k, &p);
for (int i = 0; i < n; i++) {
scanf("%d", &t);
people.push_back(t);
}
for (int i = 0; i < k; i++) {
scanf("%d", &t);
keys.push_back(t);
}
sort(people.begin(), people.end());
sort(keys.begin(), keys.end());
vector<vector<int> > f = vector<vector<int> >(n, vector<int>(k, INT_MAX));
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
int minCost = INT_MAX;
if (i == 0) {
minCost = 0;
} else {
for (int x = 0; x < j; x++) {
minCost = min(minCost, f[i - 1][x]);
}
}
f[i][j] = max(abs(people[i] - keys[j]) + abs(p - keys[j]), minCost);
}
}
int ans = INT_MAX;
for (int i = 0; i < k; i++) {
ans = min(ans, f[n - 1][i]);
}
printf("%d", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
const int M = 2e3 + 5;
const long long INF = (long long)1e16;
long long Abs(long long d) { return d >= 0 ? d : -d; }
long long dp[N][M], A[N], B[M];
int main() {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
dp[i][j] = INF;
}
}
int n, k;
long long p;
cin >> n >> k >> p;
for (int i = 1; i <= n; ++i) cin >> A[i];
for (int i = 1; i <= k; ++i) cin >> B[i];
sort(A + 1, A + n + 1);
sort(B + 1, B + k + 1);
for (int i = 1; i <= k; ++i) {
dp[1][i] = min(Abs(A[1] - B[i]) + Abs(B[i] - p), dp[1][i - 1]);
}
for (int i = 2; i <= n; ++i) {
for (int j = i; j <= k; ++j) {
dp[i][j] = min(max(dp[i - 1][j - 1], Abs(A[i] - B[j]) + Abs(B[j] - p)),
dp[i][j - 1]);
}
}
cout << dp[n][k];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, p, v[200005], u[200005];
long long r = 1e18;
int main() {
cin >> n >> m >> p;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= m; i++) cin >> u[i];
sort(v + 1, v + n + 1);
sort(u + 1, u + m + 1);
for (int i = 1; i <= m - n + 1; i++) {
long long s = 0;
for (int j = 1; j <= n; j++) {
int k = i + j - 1;
s = max(s, 1ll * abs(u[k] - v[j]) + abs(p - u[k]));
}
r = min(r, s);
}
cout << r;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, pos, a[2010], b[2010], dp[2010][2010];
inline int read() {
int s = 0, w = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') w = -1;
for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
return s * w;
}
int calc(int i, int j) { return abs(a[i] - b[j]) + abs(b[j] - pos); }
int main() {
n = read(), m = read(), pos = read();
for (int i = 1; i <= n; ++i) a[i] = read();
for (int i = 1; i <= m; ++i) b[i] = read();
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
for (int i = 1; i <= n; ++i) {
dp[i][i - 1] = 2e9;
for (int j = i; j <= m; ++j)
dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1], calc(i, j)));
}
printf("%d\n", dp[n][m]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const string TASK = "";
const int maxn = 2e3 + 1;
long long n, k, p, a[maxn], b[maxn], d[maxn][maxn];
bool f[maxn], fl;
void Enter() {
cin >> n >> k >> p;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= k; ++i) cin >> b[i];
}
void Init() {
sort(a + 1, a + n + 1);
sort(b + 1, b + k + 1);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= k; ++j) {
d[i][j] = abs(a[i] - b[j]) + abs(b[j] - p);
}
}
bool Check(long long h) {
fill(f + 1, f + k + 1, 0);
for (int i = 1; i <= n; ++i) {
fl = 0;
for (int j = 1; j <= k; ++j)
if (!f[j] && d[i][j] <= h) {
f[j] = 1;
fl = 1;
break;
}
if (!fl) return 0;
}
}
void Solve() {
long long l = 0;
long long r = 2e9;
while (l <= r) {
long long m = (l + r) / 2;
if (!Check(m))
l = m + 1;
else
r = m - 1;
}
cout << l;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
Enter();
Init();
Solve();
}
|
#include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, cx, cy;
bool valid() {
return (ax * (by - cy)) + (bx * (cy - ay)) + (cx * (ay - by)) != 0LL;
}
int main() {
while (scanf("%lld %lld %lld %lld %lld %lld", &ax, &ay, &bx, &by, &cx, &cy) ==
6) {
long long ab = ((ax - bx) * (ax - bx)) + ((ay - by) * (ay - by));
long long bc = ((bx - cx) * (bx - cx)) + ((by - cy) * (by - cy));
puts(valid() && ab == bc ? "Yes" : "No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b, e / 2);
return power(b * b, e / 2);
}
template <typename T, typename U>
static inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << '(' << p.first << "," << p.second << ')';
}
int _runtimeTerror_() {
long long a[2], b[2], c[2];
cin >> a[0] >> a[1] >> b[0] >> b[1] >> c[0] >> c[1];
bool ans = true;
auto dis = [&](long long x, long long y, long long z, long long w) {
return (z - x) * (z - x) + (w - y) * (w - y);
};
if (dis(a[0], a[1], b[0], b[1]) != dis(b[0], b[1], c[0], c[1])) ans = false;
if ((c[1] - b[1]) * (b[0] - a[0]) == (b[1] - a[1]) * (c[0] - b[0]))
ans = false;
cout << (ans ? "Yes" : "No");
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) _runtimeTerror_();
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 if (y % 2 == 0)
return power(x, y / 2) * power(x, y / 2);
else
return x * power(x, y / 2) * power(x, y / 2);
}
double slope(long long int x1, long long int y1, long long int x2,
long long int y2) {
return (double)((double)(y2 - y1) / (x2 - x1));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
long long int dab = power((bx - ax), 2) + power((by - ay), 2);
long long int dbc = power((cx - bx), 2) + power((cy - by), 2);
if (dab != dbc) {
cout << "No\n";
} else if (slope(ax, ay, bx, by) == slope(bx, by, cx, cy)) {
cout << "No\n";
} else {
cout << "Yes\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "sz:" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
const ll d1 = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
const ll d2 = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);
if (d1 == d2) {
const ll dx1 = bx - ax;
const ll dy1 = by - ay;
const ll dx2 = cx - ax;
const ll dy2 = cy - ay;
if (dx1 * dy2 == dx2 * dy1) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
} else {
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int RNG = 100003;
const int MOD1 = 1e9 + 7;
const int MOD2 = 1e9 + 87;
const double pi = 2 * acos(0.0);
inline int _Int() {
int x;
scanf("%d", &x);
return x;
}
inline long long _LLi() {
long long x;
scanf("%lld", &x);
return x;
}
void pruts() {
puts("-1");
exit(EXIT_SUCCESS);
}
int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1};
int rX[] = {1, 1, 2, 2, -1, -1, -2, -2};
int rY[] = {2, -2, 1, -1, 2, -2, 1, -1};
template <class T>
T tri_Area(T x1, T y1, T x2, T y2, T x3, T y3) {
return abs(x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2));
};
template <class T>
T Distance(T x1, T y1, T x2, T y2) {
return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
};
template <class T>
T bigMod(T n, T p, T m) {
if (p == 0) return 1;
if (p & 1) return (n * bigMod(n, p - 1, m)) % m;
T x = bigMod(n, p / 2, m);
return (x * x) % m;
};
int Case;
int sset(int N, int pos) { return N = N | (1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
long long P[10];
void Hunger() {
for (int i = 0; i < 6; i++) P[i] = _Int();
long long d1 = Distance(P[0], P[1], P[2], P[3]);
long long d2 = Distance(P[4], P[5], P[2], P[3]);
long long d = tri_Area(P[0], P[1], P[2], P[3], P[4], P[5]);
if ((!d))
puts("No");
else if (d1 != d2)
puts("No");
else
puts("Yes");
}
int main() {
Hunger();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
long long int pp = (b == 0) ? 1 : power(a, b >> 1, m);
pp = (pp * pp) % m;
if (b & 1) pp = (pp * a) % m;
return pp;
}
long long int dist(long long int a, long long int b, long long int c,
long long int d) {
return ((a - c) * (a - c) + (b - d) * (b - d));
}
signed main() {
long long int a, b, c, d, e, f;
scanf("%lld", &(a));
scanf("%lld", &(b));
scanf("%lld", &(c));
scanf("%lld", &(d));
scanf("%lld", &(e));
scanf("%lld", &(f));
if ((d - b) * (e - c) == (c - a) * (f - d))
puts("No");
else {
if (dist(a, b, c, d) == dist(c, d, e, f))
puts("Yes");
else
puts("No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
long long int d1, d2, d3;
d1 = (a - c) * (a - c) + (b - d) * (b - d);
d2 = (a - e) * (a - e) + (b - f) * (b - f);
d3 = (c - e) * (c - e) + (d - f) * (d - f);
if ((d1 != d3) || ((d - b) * (e - c) == (f - d) * (c - a))) {
cout << "No";
} else {
cout << "Yes";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool equal(long long ax, long long ay, long long bx, long long by, long long cx,
long long cy) {
return ((bx - ax) * (bx - ax) + (by - ay) * (by - ay)) ==
((cx - bx) * (cx - bx) + (cy - by) * (cy - by));
}
bool collinear(long long ax, long long ay, long long bx, long long by,
long long cx, long long cy) {
return ((by - ay) * (cx - bx)) == ((cy - by) * (bx - ax));
}
int main() {
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (!collinear(ax, ay, bx, by, cx, cy) && equal(ax, ay, bx, by, cx, cy))
cout << "Yes";
else
cout << "No";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long xxx1, yyy1, xxx2, yyy2, xxx3, yyy3;
double eps = 1e-9;
struct Point {
long long x, y;
Point(long long _x = 0, long long _y = 0) {
x = _x;
y = _y;
}
};
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
Point operator*(Point A, double p) { return Point(p * A.x, p * A.y); }
Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); }
Point operator-(Point A) { return Point(-A.x, -A.y); }
long long Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }
long long getDis(long long xx1, long long yy1, long long xx2, long long yy2) {
return (xx1 - xx2) * (xx1 - xx2) + (yy1 - yy2) * (yy1 - yy2);
}
int main() {
while (~scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &xxx1, &yyy1, &xxx2, &yyy2,
&xxx3, &yyy3)) {
long long d1 = getDis(xxx1, yyy1, xxx2, yyy2);
long long d2 = getDis(xxx2, yyy2, xxx3, yyy3);
Point v1 = Point(xxx2 - xxx1, yyy2 - yyy1);
Point v2 = Point(xxx3 - xxx1, yyy3 - yyy1);
long long judge = Cross(v1, v2);
if (d1 == d2 && judge)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int64_t dist(int64_t x1, int64_t y1, int64_t x2, int64_t y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int main() {
int64_t x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
int64_t ab = dist(x1, y1, x2, y2);
int64_t bc = dist(x2, y2, x3, y3);
if ((y1 - y2) * (x2 - x3) == (y2 - y3) * (x1 - x2)) {
cout << "No";
return 0;
}
cout << (ab == bc ? "Yes" : "No");
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
long long ax, ay, bx, by, cx, cy, ab, bc;
double slopeAB, slopeBC;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (ax == cx && ay == cy) {
cout << "Yes\n";
} else {
ab = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
bc = (cx - bx) * (cx - bx) + (cy - by) * (cy - by);
slopeAB = (double)(ay - by) / (double)(ax - bx);
slopeBC = (double)(by - cy) / (double)(bx - cx);
if (ab == bc && slopeAB != slopeBC) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
long long k1 = (by - ay) * (cx - ax);
long long k2 = (cy - ay) * (bx - ax);
if (k1 == k2) {
cout << "No" << endl;
} else {
long long dis1 = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
long long dis2 = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);
if (dis1 == dis2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, k;
long long x1, y1, x2, y2, x3, y3;
while (
~scanf("%lld %lld %lld %lld %lld %lld", &x1, &y1, &x2, &y2, &x3, &y3)) {
long long a = (y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1);
long long c = (y3 - y2) * (y3 - y2) + (x3 - x2) * (x3 - x2);
if (c == a && ((y3 - y2) * (x2 - x1) != (y2 - y1) * (x3 - x2)))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int main() {
unsigned long long ax, ay, bx, by, cx, cy;
while (
~scanf("%llu %llu %llu %llu %llu %llu", &ax, &ay, &bx, &by, &cx, &cy)) {
unsigned long long ab = ((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
unsigned long long bc = ((bx - cx) * (bx - cx) + (by - cy) * (by - cy));
if (!(ab == bc)) {
printf("No\n");
continue;
}
if (2 * bx == ax + cx && 2 * by == ay + cy)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
double midx = (ax + cx) / 2, midy = (ay + cy) / 2;
if (midx == bx && midy == by)
cout << "No\n";
else {
if (abs((cy - ay) * (midy - by) + (cx - ax) * (midx - bx)) <= 1e-7)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
double p = ax - bx;
double q = ay - by;
double r = bx - cx;
double s = by - cy;
if (p / q == r / s) {
cout << "no";
return 0;
}
double ans = (ax - bx) * (ax - bx) + (ay - by) * (ay - by) -
(cx - bx) * (cx - bx) - (cy - by) * (cy - by);
if (ans == 0)
cout << "yes";
else
cout << "no";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long double ax, bx, cx, ay, by, cy, d1, d2;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)) +
sqrt((bx - cx) * (bx - cx) + (by - cy) * (by - cy)) ==
sqrt((ax - cx) * (ax - cx) + (ay - cy) * (ay - cy))) {
cout << "NO";
return 0;
}
d1 = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
d2 = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);
if (d1 == d2)
cout << "Yes";
else
cout << "No";
}
|
#include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, cx, cy;
long long A, B, C;
long long sqr(long long x) { return x * x; }
long long bc(long long x1, long long y1, long long x2, long long y2) {
return sqr(x1 - x2) + sqr(y1 - y2);
}
int main() {
cin >> ax >> ay >> bx >> by >> cx >> cy;
C = bc(ax, ay, bx, by);
A = bc(bx, by, cx, cy);
B = bc(ax, ay, cx, cy);
if (C == A) {
if (ax + cx == 2 * bx && ay + cy == 2 * by) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
} else {
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long MAX = 1e17;
int main() {
ios_base::sync_with_stdio(0);
;
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if ((by - ay) * (cx - bx) == (cy - by) * (bx - ax)) {
cout << "No" << endl;
return 0;
;
}
if (((ax - bx) * (ax - bx) + (ay - by) * (ay - by)) ==
((bx - cx) * (bx - cx) + (by - cy) * (by - cy))) {
cout << "Yes" << endl;
return 0;
;
}
cout << "No" << endl;
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
long long int x, y, z;
x = (d - b) * (d - b) + (c - a) * (c - a);
y = (f - d) * (f - d) + (e - c) * (e - c);
z = (a - c) * (f - d) - (c - e) * (d - b);
if (x != y) {
printf("No");
return 0;
} else if (z == 0) {
printf("No");
return 0;
}
printf("Yes");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ax, ay, bx, by, cx, cy;
int main() {
scanf("%d%d%d%d%d%d", &ax, &ay, &bx, &by, &cx, &cy);
if (ax == bx && bx == cx) {
printf("No\n");
return 0;
}
if ((long long)(by - ay) * (cx - bx) == (long long)(cy - by) * (bx - ax)) {
printf("No\n");
return 0;
}
long long ab =
(long long)(bx - ax) * (bx - ax) + (long long)(by - ay) * (by - ay);
long long bc =
(long long)(cx - bx) * (cx - bx) + (long long)(cy - by) * (cy - by);
if (ab == bc)
printf("Yes\n");
else
printf("No\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int _;
long long a1, a2, b1, b2, c1, c2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;
if ((c2 - b2) * (c1 - a1) == (c2 - a2) * (c1 - b1)) {
cout << "No";
} else if ((a1 - b1) * (a1 - b1) + (a2 - b2) * (a2 - b2) ==
(b1 - c1) * (b1 - c1) + (b2 - c2) * (b2 - c2)) {
cout << "Yes";
} else
cout << "No";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int ax, ay, bx, by, cx, cy;
scanf("%lld%lld%lld%lld%lld%lld", &ax, &ay, &bx, &by, &cx, &cy);
long long int l1 = ((by - ay) * (by - ay) + (bx - ax) * (bx - ax));
long long int l2 = ((cy - by) * (cy - by) + (cx - bx) * (cx - bx));
int mark = 0;
if ((ax == bx && ax == cx) || (ay == by && ay == cy))
mark = 1;
else {
double k1 = (by - ay) * 1.0 / (bx - ax);
double k2 = (cy - by) * 1.0 / (cx - bx);
if (k1 == k2) mark = 1;
}
if (!mark && l1 == l2)
printf("Yes\n");
else
printf("No\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
long long s, s1, s2;
s1 = ((x2 - x1) * (y3 - y1));
s2 = (x3 - x1) * (y2 - y1);
if (s1 - s2 != 0 && ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) ==
(x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2)))
cout << "Yes";
else
cout << "no";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10010;
const double eps = 1e-6;
int n, m;
struct Point {
long long x, y;
} p1, p2, p3;
long long crosspro(Point a, Point b, Point c) {
long long sum =
a.x * b.y + b.x * c.y + c.x * a.y - b.x * a.y - c.x * b.y - a.x * c.y;
return sum;
}
long long dist(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int main() {
int i, j, k;
while (~scanf("%lld%lld%lld%lld%lld%lld", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x,
&p3.y)) {
long long ans = crosspro(p1, p2, p3);
if (ans) {
if (dist(p1, p2) == dist(p2, p3))
printf("Yes\n");
else
printf("No\n");
} else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if ((cy - by) * (bx - ax) == (by - ay) * (cx - bx))
cout << "No";
else if (sqrt((by - ay) * (by - ay) + (bx - ax) * (bx - ax)) !=
sqrt((cy - by) * (cy - by) + (cx - bx) * (cx - bx)))
cout << "No";
else
cout << "Yes";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, e, f;
int p;
cin >> a >> b >> c >> d >> e >> f;
if (c * f - e * d - a * f + e * b + a * d - b * c == 0) {
cout << "No\n";
return 0;
} else if ((a - c) * (a - c) + (b - d) * (b - d) ==
(e - c) * (e - c) + (f - d) * (f - d)) {
cout << "Yes\n";
return 0;
} else {
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f;
int main() {
cin >> a >> b >> c >> d >> e >> f;
long long t1 = (a - c) * (a - c) + (b - d) * (b - d);
long long t2 = (e - c) * (e - c) + (f - d) * (f - d);
if (t1 != t2 || ((c - a) == (e - c) && (f - d) == (d - b)))
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if ((by - ay) * (bx - cx) != (by - cy) * (bx - ax) &&
(cy - by) * (cy - by) + (cx - bx) * (cx - bx) ==
(bx - ax) * (bx - ax) + (by - ay) * (by - ay))
printf("yes\n");
else
printf("no\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int64_t infll = 9223372036854775807LL;
void solve() {
int64_t ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
int64_t absquared = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
int64_t bcsquared = (cx - bx) * (cx - bx) + (cy - by) * (cy - by);
int64_t areatimes2 =
abs(ax * by + bx * cy + cx * ay - ay * bx - by * cx - cy * ax);
if (absquared == bcsquared && areatimes2 > 0)
cout << "Yes\n";
else
cout << "No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long a[6];
long long f(int x, int y) {
long long ans = (a[x] - a[y]) * (a[x] - a[y]);
ans += (a[x + 1] - a[y + 1]) * (a[x + 1] - a[y + 1]);
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
for (int i = 0; i < 6; ++i) {
cin >> a[i];
}
set<long long> s;
s.insert(f(0, 2));
s.insert(f(4, 2));
long long x = (a[3] - a[1]) * (a[4] - a[2]);
long long y = (a[5] - a[3]) * (a[2] - a[0]);
if (x == y) {
cout << "No" << '\n';
;
return 0;
}
if (s.size() == 1) {
cout << "Yes" << '\n';
;
} else
cout << "No" << '\n';
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e5 + 111;
const int inf = (int)1e9 + 111;
const long long llinf = (long long)1e18 + 5;
const int MOD = (int)1e9 + 7;
long double dist(long double X1, long double Y1, long double X2,
long double Y2) {
return sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
}
int main() {
srand(time(0));
ios_base::sync_with_stdio(false);
long double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (ax == bx && bx == cx) {
cout << "No";
return 0;
}
if (ay == by && by == cy) {
cout << "No";
return 0;
}
long double k = (long double)(ay - by) / (ax - bx);
long double b = ay - k * ax;
if (cy == k * cx + b) {
cout << "No";
return 0;
}
if (dist(ax, ay, bx, by) == dist(bx, by, cx, cy)) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
double dist(double x1, double y1, double x2, double y2) {
double d = (double)((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
return d;
}
void solve() {
double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
double lenab = dist(ax, ay, bx, by);
double lenbc = dist(bx, by, cx, cy);
double lenac = dist(cx, cy, ax, ay);
if (sqrt(lenab) != sqrt(lenbc)) {
cout << "No\n";
return;
}
long long ar = ax * (by - cy) + bx * (cy - ay) + cx * (ay - by);
if (ar == 0) {
cout << "No\n";
return;
}
cout << "Yes\n";
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
long double dist1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
long double dist2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
long double dist3 = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
if (!((double)(y1 - y2) / (x1 - x2) == (double)(y1 - y3) / (x1 - x3)) &&
!(y1 == y2 && y1 == y3) && (dist1) == (dist3))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int const N = 1000020;
double m(double ax, double ay, double bx, double by) {
if (ax - bx == 0) return 1e9 + 2;
return (by - ay) / (bx - ax);
}
double d(long long ax, long long ay, long long bx, long long by) {
return (ax - bx) * (ax - bx) + (by - ay) * (by - ay);
}
double const EPS = 1e-12;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if ((ax - bx) * (by - cy) != (ay - by) * (bx - cx) and
d(ax, ay, bx, by) == d(bx, by, cx, cy))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int const N = 1000020;
double m(double ax, double ay, double bx, double by) {
if (ax - bx == 0) return 1e9 + 2;
return (by - ay) / (bx - ax);
}
double d(long long ax, long long ay, long long bx, long long by) {
return (ax - bx) * (ax - bx) + (by - ay) * (by - ay);
}
double const EPS = 1e-12;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (fabs(m(ax, ay, bx, by) - m(bx, by, cx, cy)) > EPS and
d(ax, ay, bx, by) == d(bx, by, cx, cy))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double dist_a_b =
sqrt((double)((x1 - x2) * (x1 - x2)) + (double)((y1 - y2) * (y1 - y2)));
double dist_b_c =
sqrt((double)((x2 - x3) * (x2 - x3)) + (double)((y2 - y3) * (y2 - y3)));
if (((y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2)) ||
(dist_a_b != dist_b_c)) {
cout << "No";
} else {
cout << "Yes";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long mod = pow(10, 9) + 7;
const double pi = 3.141592653589793238;
long long countdivisors(long long n) {
long long count = 0;
for (long long i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i) {
count++;
} else {
count = count + 2;
}
}
}
return count;
}
void remove(std::vector<int> &v) {
auto end = v.end();
for (auto it = v.begin(); it != end; ++it) {
end = std::remove(it + 1, end, *it);
}
v.erase(end, v.end());
}
bool isPerfectSquare(long long x) {
long long s = sqrt(x);
return (s * s == x);
}
bool isFibonacci(int n) {
return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4);
}
int digSum(int n) {
int sum = 0;
while (n > 0) {
sum += n % 10;
n = n / 10;
}
return sum;
}
long long exponentMod(long long A, long long B, long long C) {
if (A == 0) return 0;
if (B == 0) return 1;
long long y;
if (B % 2 == 0) {
y = exponentMod(A, B / 2, C);
y = (y * y) % C;
} else {
y = A % C;
y = (y * exponentMod(A, B - 1, C) % C) % C;
}
return (long long)((y + C) % C);
}
void sieve(int N) {
bool isPrime[N + 1];
for (int i = 0; i <= N; ++i) {
isPrime[i] = true;
}
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i * i <= N; ++i) {
if (isPrime[i] == true) {
for (int j = i * i; j <= N; j += i) isPrime[j] = false;
}
}
}
void solve() {
double xa, ya, xb, yb, xc, yc;
cin >> xa >> ya >> xb >> yb >> xc >> yc;
double m1 = (yb - ya) / (xb - xa);
double m2 = (yc - yb) / (xc - xb);
double m3 = (yc - ya) / (xc - xa);
if (m1 == m2 && m1 == m3) {
cout << "NO";
} else {
double d1 = sqrt(((ya - yb) * (ya - yb)) + ((xa - xb) * (xa - xb)));
double d2 = sqrt(((yc - yb) * (yc - yb)) + ((xc - xb) * (xc - xb)));
if (d1 == d2) {
cout << "YES";
} else {
cout << "NO";
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, cx, cy;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> ax >> ay >> bx >> by >> cx >> cy;
if ((by - ay) * (cx - bx) == (cy - by) * (bx - ax))
cout << "NO\n";
else if ((by - ay) * (by - ay) + (bx - ax) * (bx - ax) ==
(by - cy) * (by - cy) + (bx - cx) * (bx - cx))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long modular_pow(long long base, long long exponent, long long modulus) {
long long result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) result = (result * base) % modulus;
exponent = exponent >> 1;
base = (base * base) % modulus;
}
return result;
}
void computePrefixTable(string pat, vector<int>& v) {
int len = 0;
v[0] = 0;
int i = 1;
while (i < pat.size()) {
if (pat[i] == pat[len]) {
len++;
v[i] = len;
i++;
} else {
if (len != 0) {
len = v[len - 1];
} else {
v[i] = 0;
i++;
}
}
}
}
long long countDistinctSubstrings(string s, int i, int j) {
string r = s.substr(i, j - i + 1);
vector<int> v(r.size(), 0);
computePrefixTable(r, v);
long long tot = v.size() * (v.size() + 1) / 2;
for (int k = 0; k < v.size(); k++) {
tot -= v[k];
}
return tot;
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long numDigits(long long i) {
return i > 0 ? (long long)log10((double)i) + 1 : 1;
}
long long dist(long long ax, long long ay, long long bx, long long by) {
return (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
}
int main() {
ios_base::sync_with_stdio(false);
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (dist(ax, ay, bx, by) != dist(bx, by, cx, cy)) {
cout << "No" << endl;
return 0;
}
if (4 * dist(ax, ay, bx, by) == dist(ax, ay, cx, cy)) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long sqr(int a) { return 1ll * a * a; }
int main() {
int ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (sqr(bx - ax) + sqr(by - ay) == sqr(cx - bx) + sqr(cy - by) &&
1ll * (bx - ax) * (cy - by) != 1ll * (cx - bx) * (by - ay))
cout << "Yes";
else
cout << "No";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
long double d1 = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
long double d2 = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);
if ((cx + ax) / 2 == bx && (cy + ay) / 2 == by)
cout << "NO";
else if (d1 == d2)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const double eps = 1e-10;
long long dis(long long ax, long long ay, long long bx, long long by) {
return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
}
int main() {
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
double a = sqrt(1.0 * dis(bx, by, cx, cy)),
b = sqrt(1.0 * dis(cx, cy, ax, ay)),
c = sqrt(1.0 * dis(ax, ay, bx, by));
if (dis(ax, ay, bx, by) == dis(bx, by, cx, cy)) {
if (fabs(b - a - c) < eps)
printf("No\n");
else
printf("Yes\n");
} else
printf("No\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if (((ax - bx) * (ax - bx) + (ay - by) * (ay - by) ==
((cx - bx) * (cx - bx) + (cy - by) * (cy - by))) &&
((cy - by) * (bx - ax) != (by - ay) * (cx - bx)))
printf("Yes");
else
printf("No");
}
int main() {
int t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int M = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
long long int ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
long long int l = 4 * (ax - bx) * (by - cy) - 4 * (bx - cx) * (ay - by);
if (l != 0) {
long long int a, b;
a = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
b = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);
if (a == b)
cout << "Yes\n";
else
cout << "No\n";
} else
cout << "No\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<unsigned long long, unsigned long long> a, b, c;
cin >> a.first >> a.second;
cin >> b.first >> b.second;
cin >> c.first >> c.second;
if (a != b && b != c && a != c) {
if ((b.second - a.second) * (b.second - a.second) +
(b.first - a.first) * (b.first - a.first) ==
(b.second - c.second) * (b.second - c.second) +
(b.first - c.first) * (b.first - c.first) &&
(2 * b.first != a.first + c.first ||
2 * b.second != a.second + c.second))
cout << "YES";
else
cout << "NO";
} else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
long double a1, a2, b2, b1, c2, c1;
cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;
;
long double x = (pow((a1 - b1), 2)) + (pow((a2 - b2), 2));
long double z = (pow((b1 - c1), 2)) + (pow((b2 - c2), 2));
if (z == x) {
if (a1 + c1 != 2 * b1 || a2 + c2 != 2 * b2)
cout << "YES";
else
cout << "NO";
} else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
void solveTask() {
long long x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
bool ok1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ==
((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
bool ok2 = ((x3 - x1) * (y2 - y1)) != ((y3 - y1) * (x2 - x1));
if (ok1 && ok2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
solveTask();
ios_base::sync_with_stdio(false);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.