text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { int a, c[100001], d, e = 0, i, n; scanf("%d%d", &n, &a); d = n - 1; for (i = 0; i < n; i++) { scanf("%d", &c[i]); } sort(c, c + n); for (i = 0; i < d; i++) { e += c[i]; } if (e <= a) { printf("YES\n"); } else printf("NO\n"); }
#include <bits/stdc++.h> using namespace std; const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; const int N = 1e6 + 10; const int mod = 1e9 + 7; const double pi = acos(-1); const int INF = 0x3f3f3f3f; int a[N]; int n, s, K; int main() { ios::sync_with_stdio(0); cin >> n >> s; for (int i = 1; i <= n; ++i) { cin >> a[i]; } sort(a + 1, a + 1 + n); long long sum = 0; for (int i = 1; i < n; ++i) { if (sum + a[i] <= s) { sum += a[i]; } else { return puts("NO"), 0; } } puts("YES"); return 0; }
#include <bits/stdc++.h> const int dx[] = {0, -1, 0, 1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1}; const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2}; using namespace std; inline int sum(int x) { return (x * (x + 1)) / 2; } int main(int argc, char const *argv[]) { int n, s; scanf("%d %d", &n, &s); vector<int> vol(n); for (int i = 0; i < n; i++) scanf("%d", &vol[i]); sort(vol.begin(), vol.end()); int sum = 0; for (int i = 0; i < n - 1; i++) sum += vol[i]; if (sum <= s) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> int n, s, x, max = -111; int main() { scanf("%d%d", &n, &s); while (n--) { scanf("%d", &x); s = s - x; if (x > max) max = x; } if (s + max >= 0) printf("YES"); else printf("NO"); return 0; }
#include <bits/stdc++.h> int main() { int n, s, a, x = 0, max = 0, i, j; scanf("%d %d", &n, &s); for (i = 1; i <= n; i++) { scanf("%d", &a); x = x + a; if (a > max) { max = a; } } j = x - max; if (j > s) { printf("NO\n"); } else { printf("YES\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int a[n], i = 0, sum = 0, max = 0; while (i < n) { cin >> a[i]; sum += a[i]; max = max > a[i] ? max : a[i]; i++; } if ((sum - max) > s) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s, p = 0; cin >> n >> s; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n - 1; i++) p += a[i]; if (p <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s, sum = 0, m = 0; cin >> n >> s; int un; for (int i = 1; i <= n; i++) { cin >> un; sum += un; m = max(m, un); } if (sum - m <= s) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, i, j, k, tc, t; int n, m, cnt = 0; int ara[10001]; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &ara[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (ara[i] > ara[j]) { int tmp = ara[i]; ara[i] = ara[j]; ara[j] = tmp; } } } j = 0; k = 0; for (i = 0; i < n; i++) { if (j == n - 1) break; if (k + ara[i] > m) { printf("NO\n"); return 0; } if (ara[i] != 0 && k + ara[i] <= m) { k += ara[i]; j++; } } if (j != n - 1) printf("NO\n"); else printf("YES\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s, arr[120], sum; while (scanf("%d%d", &n, &s) != EOF) { sum = 0; memset(arr, 0, 120); for (int i = 0; i < n; i++) scanf("%d", &arr[i]); sort(arr, arr + n); for (int j = 0; j < n - 1; j++) sum = sum + arr[j]; if (sum <= s) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, c, p, s, m; void setup() {} void solve() { cin >> n >> c; for (int i = 1; i <= n; ++i) { cin >> p; s += p; m = max(m, p); } if (s - m <= c) cout << "YES"; else cout << "NO"; } int main() { setup(); solve(); return 0; }
#include <bits/stdc++.h> int main() { int n, s, i, sum = 0, max = 0; scanf("%d %d", &n, &s); int arr[n]; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); sum = sum + arr[i]; if (arr[i] > max) max = arr[i]; } if (sum - max > s) printf("NO"); else printf("YES"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int mug; int collect = 0; int largest = 0; for (int i = 0; i < n; i++) { cin >> mug; if (largest < mug) largest = mug; collect = collect + mug; } if ((collect - largest) <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int a[n], _max = 0, sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; _max = max(_max, a[i]); sum += a[i]; } if (sum - _max <= s) cout << "YES\n"; else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long int n; cin >> n; long long int m; cin >> m; long long int minv = INT_MAX, maxv = INT_MIN; long long int sum = 0; while (n--) { long long int x; cin >> x; sum += x; if (x > maxv) maxv = x; } if (sum - maxv <= m) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int MAX = 100005; int mugs[MAX]; int main() { ios_base::sync_with_stdio(0); int n, s; cin >> n >> s; for (int i = (0); i < (n); ++i) cin >> mugs[i]; sort(mugs, mugs + n); int sum = accumulate(mugs, mugs + (n - 1), 0); if (sum <= s) cout << "YES" << '\n'; else cout << "NO" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, s, a[101], x = 0, t; cin >> n >> s; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) for (j = i; j <= n; j++) if (a[i] > a[j]) { t = a[i]; a[i] = a[j]; a[j] = t; } for (i = 1; i <= n - 1; i++) x = x + a[i]; if (x > s) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int sum = 0; int maxx = 0; for (int i = 0; i < n; ++i) { int x; cin >> x; maxx = max(x, maxx); sum += x; } cout << (sum - maxx > s ? "NO" : "YES") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long int gcd(long int a, long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int n, s; cin >> n >> s; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); int sum = 0; for (int i = 0; i < n - 1; i++) sum += v[i]; if (sum <= s) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n, s; cin >> n >> s; for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); for (int i = 0; i < n - 1; i++) s -= a[i]; if (s >= 0) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return (gcd(b, a % b)); } int lcm(int a, int b) { return (a / gcd(a, b) * b); } int mod(int a, int b) { if (a < 0) return ((b + a) % b); else return a % b; } vector<string> splitAsString(string a) { vector<string> v; string w; stringstream s; s << a; while (s >> w) v.push_back(w); return v; } string _UCASE(string a) { for (int i = 0; i < a.size(); i++) if (a[i] >= 'a' && a[i] <= 'z') a[i] = a[i] - 'a' + 'A'; return a; } string _LCASE(string a) { for (int i = 0; i < a.size(); i++) if (a[i] >= 'A' && a[i] <= 'Z') a[i] = a[i] - 'A' + 'a'; return a; } bool _FIND(vector<int> v, int a) { if (find(v.begin(), v.end(), a) == v.end()) return 0; return 1; } int main() { int n, s, sum = 0, maxi = 1; cin >> n >> s; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; if (v[i] > maxi) maxi = v[i]; } sum -= maxi; if (sum <= s) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; while (cin >> n >> s) { int sum = 0; int maxvar = 0; for (int i = 1; i <= n; ++i) { int x; cin >> x; sum += x; maxvar = max(maxvar, x); } cout << (sum - maxvar <= s ? "YES" : "NO") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s, sum = 0, mx = 0, x; cin >> n >> s; for (int i = 0; i < n; i++) cin >> x, sum += x, mx = max(mx, x); sum -= mx; if (sum <= s) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, s, p, a[105]; int main() { scanf("%d%d", &n, &s); for (int i = 1; i <= n; i++) scanf("%d", a + i); sort(a + 1, a + n + 1); for (int i = 1; i < n; i++) p += a[i]; if (p <= s) puts("YES"); else puts("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, s; cin >> n >> s; int t; int m = 0; for (int i = 0; i < n; i++) { cin >> t; s -= t; m = m < t ? t : m; }; s += m; if (s < 0) cout << "NO\n"; else cout << "YES\n"; }
#include <bits/stdc++.h> using namespace std; int a[10000]; int main() { int n, s, i, sum; cin >> n >> s; sum = 0; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i <= n - 2; i++) sum += a[i]; if (sum <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int arr[101]; int main() { int n, v, sum = 0; cin >> n >> v; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } sort(arr, arr + n); sum -= arr[n - 1]; if (sum <= v) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, s; int a[110]; int main() { cin >> n >> s; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int sum = 0; for (int i = 0; i < n - 1; i++) sum += a[i]; if (sum <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, a, k, m = 0, sum = 0, s; cin >> n >> s; for (i = 0; i < n; i++) { cin >> a; if (a > m) m = a; sum = sum + a; } sum = sum - m; if (s >= sum) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; int a[1005]; int cmp(int a, int b) { return a > b; } long long read() { long long w = 1, c, ret; while ((c = getchar()) > '9' || c < '0') w = (c == '-' ? -1 : 1); ret = c - '0'; while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + c - '0'; return ret * w; } int main() { int n, s; n = read(); s = read(); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1, cmp); int sum = 0; for (int i = 1; i <= n; i++) { sum += a[i]; } sum -= a[1]; if (sum > s) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int a[120]; int n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int s = 0; int j; for (j = 1; j < n; j++) { s += a[j]; if (s > m) break; } if (j < n) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s, arr[100], sum = 0; cin >> n >> s; for (int i = 0; i < n; i++) cin >> arr[i], sum += arr[i]; for (int i = 0; i < n; i++) { sum -= arr[i]; if (sum <= s) { cout << "YES"; return 0; } sum += arr[i]; } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int a[n]; long long int sum = 0; int maxi = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; maxi = max(maxi, a[i]); } if (sum - maxi <= s) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, total, i, k, mx = -1; ; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> k; if (mx <= k) mx = k; total += k; } if (m - (total - mx) >= 0) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, c, sum; int arr[1000]; sum = 0; cin >> n >> c; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int i = 0; i < n - 1; i++) { sum += arr[i]; } if (sum <= c) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int max = -1000000000; int s = 0; for (int i = 0; i < n; ++i) { int q; cin >> q; s += q; if (q > max) max = q; } s -= max; if (m >= s) { cout << "YES\n"; } else { cout << "NO\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int k; int max; int sum = 0; for (int i = 0; i < n; ++i) { cin >> k; if (i == 0) max = k; else { if (k > max) max = k; } sum += k; } if ((sum - max) <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> int main() { int tmax, i, sum, n, v, temp; scanf("%d%d", &n, &v); tmax = -0xfffffff; sum = 0; for (i = 1; i <= n; i++) { scanf("%d", &temp); if (temp > tmax) { tmax = temp; } sum += temp; } if (sum - tmax > v) { printf("NO\n"); } else { printf("YES\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long ans, maxx, s, n, a; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { cin >> a; ans += a; if (a > maxx) maxx = a; } if (ans - maxx <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s, h, max = -1, sum = 0; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> h; sum += h; if (h > max) max = h; } sum -= max; if (sum <= s) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; cin >> n >> k; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i < n - 1; i++) k = k - a[i]; if (k >= 0) cout << "YES\n"; else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int ans = -1e9; int main() { int n, s, sum = 0; cin >> n >> s; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; ans = max(a[i], ans); } if (sum - ans <= s) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; int a[1005]; int cmp(int a, int b) { return a > b; } long long read() { long long w = 1, c, ret; while ((c = getchar()) > '9' || c < '0') w = (c == '-' ? -1 : 1); ret = c - '0'; while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + c - '0'; return ret * w; } int main() { int n, s; n = read(); s = read(); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); int sum = 0; for (int i = 1; i <= n; i++) { sum += a[i]; } sum -= a[n]; if (sum > s) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, a[100005] = {}, s, sum = 0; cin >> n >> s; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n - 1; i++) sum += a[i]; if (sum > s) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n, s; int sum = 0, MAX = 0; scanf("%d%d", &n, &s); while (n--) { int num; scanf("%d", &num); sum += num; MAX = max(MAX, num); } if (sum - MAX > s) printf("NO\n"); else printf("YES\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int n, m; cin >> n >> m; int a[2222]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); qsort(a, n, sizeof(a[0]), cmp); int flag = 1; int sum = 0; for (int i = 0; i < n - 1; i++) { sum += a[i]; if (sum > m) { cout << "NO" << endl; flag = 0; break; } } if (flag) cout << "YES" << endl; return 0; }
#include <bits/stdc++.h> int arr[100]; int main() { int n, s; scanf("%d %d", &n, &s); int i, j, k, sum = 0; for (i = 0; i < n; i++) scanf("%d", &arr[i]); for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (arr[i] > arr[j]) { k = arr[i]; arr[i] = arr[j]; arr[j] = k; } } } for (i = 0; i < n - 1; i++) sum = sum + arr[i]; if (sum <= s) printf("YES"); else printf("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int in; int sum = 0; int maxx = -1; for (int i = 0; i < n; i++) { cin >> in; sum += in; maxx = max(maxx, in); } if (sum - maxx <= s) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, s, a[1000], sum; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a + 0, a + n); for (int i = 0; i < n - 1; i++) { sum += a[i]; } if (sum <= s) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t = 0; int n, v; cin >> n >> v; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n - 1; i++) { t = t + a[i]; } if (t <= v) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x, maxn = -1, ans = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> x; ans += x; maxn = max(x, maxn); } if (ans - maxn > k) cout << "NO" << endl; else cout << "YES" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int Tv = 0; int mx = -1; for (int i = 0; i < n; i++) { int p; cin >> p; Tv += p; mx = max(p, mx); } if (Tv - mx <= m) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int a, c, sum = 0, v, b, m = 0, arr[105], n; scanf("%d %d", &a, &b); for (int i = 0; i < a; i++) { scanf("%d", &v); arr[i] = v; if (arr[i] > m) { m = arr[i]; n = i; } } arr[n] = 0; for (int j = 0; j < a; j++) sum += arr[j]; if (sum > b) printf("NO"); else printf("YES"); }
#include <bits/stdc++.h> int main() { int n, m, x, tp; while (scanf("%d %d", &n, &m) != EOF) { int sum = 0, rt; for (int i = 0; i < n; i++) { scanf("%d", &x); if (i == 0) tp = x; else if (tp < x) tp = x; sum += x; } if (sum - tp <= m) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int N, i, j, T, a[200]; int main() { scanf("%d %d", &N, &T); int sum = 0; for (i = 0; i < N; i++) { scanf("%d", a + i); sum += a[i]; } string ans = "NO"; for (i = 0; i < N; i++) if (sum - a[i] <= T) { ans = "YES"; break; } printf("%s\n", ans.c_str()); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const int N = 5e5 + 11; int main() { int n, s; cin >> n >> s; int mx = -inf; for (int i = 0; i < n; i++) { int x; cin >> x; mx = max(mx, x); s -= x; } s += mx; if (s < 0) puts("NO"); else puts("YES"); return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int a, b; cin >> a >> b; vector<int> v; for (int i = 0; i < a; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int mn = 0; for (int i = 0; i < a - 1; i++) { mn += v[i]; } cout << (mn <= b ? "YES\n" : "NO\n"); } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1, i = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; const double pi = 3.14159265358979323846264; inline bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { return a * b / gcd<T>(a, b); } int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } int main() { long long tc = 1; while (tc--) { long long n, s; scanf("%lld %lld", &n, &s); long long a[n]; long long sum = 0; for (long long i = 0; i < n; i++) { scanf("%lld", &a[i]); sum += a[i]; } long long max = 0; for (long long i = 0; i < n; i++) { if (max < a[i]) max = a[i]; } if (sum - max <= s) cout << "YES" << '\n'; else cout << "NO" << '\n'; } }
#include <bits/stdc++.h> using namespace std; int n, s, a[10000]; int main() { ios_base::sync_with_stdio(false); int i, tot = 0, mx = -1; cin >> n >> s; for (i = 0; i < n; i++) { cin >> a[i]; tot += a[i]; mx = max(mx, a[i]); } tot -= mx; if (tot <= s) { cout << "YES\n"; } else { cout << "NO\n"; } return 0; }
#include <bits/stdc++.h> int cmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; } int n, m, i, j, k, sum, d, t[101], tmp1, tmp2, max, min, ans, x, s; int main() { scanf("%d%d", &n, &s); min = s + 1; for (i = 0; i < n; i++) { scanf("%d", &t[i]); } qsort(t, n, 4, cmp); for (i = 0; i < n - 1; i++) { sum += t[i]; } printf("%s\n", sum <= s ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; int max = 0; int counter = 0; cin >> n >> s; for (int i = 0; i < n; i++) { int a; cin >> a; counter += a; if (a > max) { max = a; } } if (counter - max > s) { cout << "NO"; return 0; } else { cout << "YES"; return 0; } }
#include <bits/stdc++.h> using namespace std; int M, N; string s; const int MAX = 2005; const int MOD = 1000000007; int main() { int n, m; while (cin >> n >> m) { int arr[1005]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); bool b = 1; int sum = 0; for (int i = 0; i < n; i++) { if (sum <= m) sum += arr[i]; else { b = 0; break; } } puts((b) ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long MAXN = 10000001; const long long INF = 1e18; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " => " << a << "] ["; cout << '\n'; err(++it, args...); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, emp_mug; cin >> n >> emp_mug; vector<long long> a(n); for (long long i = (0); i < (n); i++) cin >> a[i]; sort((a).begin(), (a).end()); long long sum = 0; for (long long i = (0); i < (n - 1); i++) sum += a[i]; sum <= emp_mug ? cout << "YES" << '\n' : cout << "NO" << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int a[200]; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (long long i = 0; i < n - 1; i++) s -= a[i]; if (s >= 0) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; while (~scanf("%d%d", &n, &s)) { int maxv = 0; int tot = 0; int a; for (int i = 0; i < n; i++) { scanf("%d", &a); tot += a; if (a > maxv) maxv = a; } if (tot - maxv > s) printf("NO\n"); else printf("YES\n"); } }
#include <bits/stdc++.h> using namespace std; const int N = 5010; int x[N], y[N], z[N]; double sqr(double x) { return x * x; } double dis(int i, int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d%d", x + i, y + i, z + i); } double mn = 1e18; for (int i = 2; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { mn = min(mn, dis(1, i) + dis(i, j) + dis(1, j)); } } printf("%.10f\n", mn / 2); return 0; }
#include <bits/stdc++.h> using namespace std; double dis(double x1, double y1, double z1, double x2, double y2, double z2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); } int main() { int n; cin >> n; int x[n], y[n], z[n]; for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> z[i]; double d, ans = 2147483647; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { d = dis(x[i], y[i], z[i], x[j], y[j], z[j]) + dis(x[0], y[0], z[0], x[j], y[j], z[j]) + dis(x[i], y[i], z[i], x[0], y[0], z[0]); ans = min(ans, d / 2); } } cout << fixed << setprecision(10) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z; }; int n; point pt[5010]; double dist[5010][5010]; double ans = 1e12; double findDist(point a, point b) { return sqrtl((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &pt[i].x, &pt[i].y, &pt[i].z); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] = findDist(pt[i], pt[j]); } } for (int i = 2; i <= n; i++) { for (int j = i + 1; j <= n; j++) { double a, b; a = dist[1][i], b = dist[1][j]; if (a > b) swap(a, b); ans = min(ans, b + (dist[i][j] - (b - a)) / 2.0); } } cout << fixed << setprecision(7) << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; double dist(double a, double b, double c, double p, double q, double r) { return sqrt((a - p) * (a - p) + (b - q) * (b - q) + (c - r) * (c - r)); } int main() { int n; cin >> n; vector<int> x(n), y(n), z(n); for (register int i = (0); i < (int)(n); ++i) cin >> x[i] >> y[i] >> z[i]; double res = 1e10; for (register int i = (1); i < (int)(n); ++i) for (register int j = (i + 1); j < (int)(n); ++j) { double tmp = dist(x[i], y[i], z[i], x[0], y[0], z[0]); tmp += dist(x[i], y[i], z[i], x[j], y[j], z[j]); tmp += dist(x[j], y[j], z[j], x[0], y[0], z[0]); res = min(res, tmp / 2); } cout << fixed << setprecision(10) << res << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[5555], b[5555], c[5555]; double d[5555], res = 1e18; int sq(int x) { return x * x; } double dis(int x, int y) { return sqrt(sq(a[x] - a[y]) + sq(b[x] - b[y]) + sq(c[x] - c[y])); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]); for (int i = 1; i < n; i++) d[i] = dis(0, i); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) { double x = dis(i, j) + d[i] + d[j]; res = min(res, x); } printf("%.6lf\n", res / 2); return 0; }
#include <bits/stdc++.h> using namespace std; const int MaxN = 5005; const int oo = 1000000000; const long long Base = 1000000007; typedef int Tarr[MaxN]; double x[MaxN], y[MaxN], z[MaxN], res; int num[MaxN][MaxN], ber[MaxN]; int n; double sqr(double x) { return x * x; } double Dis(int i, int j) { double t = (sqr(x[i] - x[j]) + sqr(y[i] - y[j])); return sqrt(t + sqr(z[i] - z[j])); } double Min(double i, double j) { if (i < j) return i; else return j; } int main() { n = 100; cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i]; res = oo; for (int i = 2; i <= n - 1; i++) for (int j = i + 1; j <= n; j++) { res = min(res, (-Dis(1, i) + Dis(1, j) + Dis(i, j)) / 2 + Dis(1, i)); } cout << fixed << setprecision(9) << res; return 0; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1E-10; void dbg(vector<int> a) { for (size_t i = 0; i < a.size(); i++) { printf("%d ", a[i]); } printf("\n"); } void dbg(vector<vector<int> > a) { for (size_t i = 0; i < a.size(); i++) { dbg(a[i]); } } void dbg(vector<string> a) { for (size_t i = 0; i < a.size(); i++) { printf("%s\n", a[i].data()); } } void openf(const string &fname, string mode = "") { string fin = fname + ".in"; string fout = fname + ".out"; if (mode.size() == 1 && mode[0] == 'r') freopen(fin.data(), "r", stdin); if (mode.size() == 1 && mode[0] == 'w') freopen(fout.data(), "w", stdout); if (mode.size() == 2) { freopen(fin.data(), "r", stdin); freopen(fout.data(), "w", stdout); } } vector<long double> x, y, z; vector<long double> ds; inline long double dst(int i) { return sqrt(x[i] * x[i] + y[i] * y[i] + z[i] * z[i]); } inline long double C(int i, int j) { long double dx = x[i] - x[j], dy = y[i] - y[j], dz = z[i] - z[j]; return sqrt(dx * dx + dy * dy + dz * dz); } int main() { int n; cin >> n; n--; x.resize(n); y = x; z = x; long double fx, fy, fz; cin >> fx >> fy >> fz; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; x[i] -= fx; y[i] -= fy; z[i] -= fz; } ds.resize(n); for (int i = 0; i < n; i++) ds[i] = dst(i); long double m = 10000000000000.0; long double a, b, c, t; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (i == j) continue; a = ds[i]; b = ds[j]; if (a > b) swap(a, b); c = C(i, j); t = (c - (b - a)) / 2.0 + b; m = (((m) < (t)) ? (m) : (t)); } } cout.precision(10); cout << fixed << m; return 0; }
#include <bits/stdc++.h> using namespace std; void Weapons19() { cout << fixed << setprecision(16); cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); } long double dist(pair<pair<long long int, long long int>, long long int> a, pair<pair<long long int, long long int>, long long int> b) { long long int k = a.first.first - b.first.first; long long int l = a.first.second - b.first.second; long long int m = a.second - b.second; long double p = sqrt(k * k + l * l + m * m); return p; } int32_t main() { Weapons19(); long long int n; cin >> n; vector<pair<pair<long long int, long long int>, long long int>> v; for (long long int i = 0; i < n; i++) { long long int a, b, c; cin >> a >> b >> c; v.push_back({{a, b}, c}); } long double ans = 9999999.9; for (long long int i = 1; i < n; i++) { for (long long int j = i + 1; j < n; j++) { long double p = dist(v[i], v[j]) + dist(v[i], v[0]) + dist(v[j], v[0]); p /= 2.0; ans = min(ans, p); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; struct cor { int x, y, z; } a[7000]; double ans; int n; int sqr(int x) { return x * x; } double dis(int x, int y) { return sqrt(sqr(a[x].x - a[y].x) + sqr(a[x].y - a[y].y) + sqr(a[x].z - a[y].z)); } int main() { cout.setf(ios::fixed); cout.precision(6); cin >> n; for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y >> a[i].z; ans = dis(0, 1) + dis(1, 2) + dis(0, 2); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, dis(i, j) + dis(0, i) + dis(0, j)); cout << ans / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int x[5050], y[5050], z[5050]; double ans; inline int sqr(int a) { return a * a; } double dis(int i, int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", x + i, y + i, z + i); ans = 1E9; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) if (dis(0, i) + dis(0, j) + dis(i, j) < ans) ans = dis(0, i) + dis(0, j) + dis(i, j); printf("%.10lf\n", ans / 2); }
#include <bits/stdc++.h> using namespace std; double ans = -1, x[6000], y[6000], z[6000], d[6000]; int n; void qsort(int l, int r) { int i = l, j = r, m = (l + r) / 2; double w = d[m]; while (i <= j) { while (d[i] < w) i++; while (d[j] > w) j--; if (i <= j) { double tmp = d[i]; d[i] = d[j]; d[j] = tmp; tmp = x[i]; x[i] = x[j]; x[j] = tmp; tmp = y[i]; y[i] = y[j]; y[j] = tmp; tmp = z[i]; z[i] = z[j]; z[j] = tmp; i++; j--; } } if (i < r) qsort(i, r); if (j > l) qsort(l, j); } double sqr(double x) { return x * x; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i]; for (int i = 1; i <= n; i++) d[i] = sqrt(sqr(x[i] - x[1]) + sqr(y[i] - y[1]) + sqr(z[i] - z[1])); qsort(1, n); for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) { double when = 0; double dist = sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); dist -= d[j] - d[i]; when = d[j] + dist / 2; if (ans < 0 || when < ans) ans = when; } printf("%.19lf", ans); }
#include <bits/stdc++.h> using namespace std; unsigned long long f(string &s, string n) { if (n.size() == s.size()) { if (n == s) return 0; return 1; } int a = n[n.size() - 1] - 48; int b = s[n.size()] - 48; if ((a + b) % 2 == 0) { return f(s, n + char((a + b) / 2 + 48)); } else return f(s, n + char((a + b) / 2 + 48)) + f(s, n + char((a + b) / 2 + 1 + 48)); } double dist(vector<int> &a, vector<int> &b) { return sqrt((double)((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]))); } int main() { int n; cin >> n; vector<vector<int> > a(n, vector<int>(3, 0)); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; double mn = dist(a[0], a[1]) + dist(a[0], a[2]) + dist(a[1], a[2]); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) mn = min(mn, dist(a[i], a[j]) + dist(a[0], a[i]) + dist(a[0], a[j])); printf("%.10f\n", mn / 2.0); return 0; }
#include <bits/stdc++.h> using namespace std; int n; struct Nodes { double x, y, z; } p[5010]; double sqr(double x) { return x * x; } double dis(int i, int j) { return sqrt(sqr(p[i].x - p[j].x) + sqr(p[i].y - p[j].y) + sqr(p[i].z - p[j].z)); } int main() { int i, j, k; double ans; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) { scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z); } ans = 1e100; for (i = 2; i <= n; i++) { for (j = 2; j < i; j++) { ans = min(ans, dis(1, i) + dis(1, j) + dis(i, j)); } } printf("%.8f\n", ans / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, x[5009], y[5009], z[5009]; double ans = 1234567890; double d(int i, int j) { return sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j]))); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &z[i]); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = ((ans < d(0, i) + d(0, j) + d(i, j)) ? (ans) : (d(0, i) + d(0, j) + d(i, j))); printf("%.8lf", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; inline long long int max(long long int a, long long int b, long long int c) { return max(max(a, b), c); } inline long long int min(long long int a, long long int b, long long int c) { return min(min(a, b), c); } inline long long int max(long long int a, long long int b) { return (a > b) ? a : b; } inline long long int min(long long int a, long long int b) { return (a < b) ? a : b; } inline long long int mul(long long int x, long long int y, long long int mod_) { return ((x % mod_) * 1LL * (y % mod_)) % mod_; } long long int power(long long int a, long long int n) { long long int p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } long long int powm(long long int a, long long int n, long long int mod_) { long long int p = 1; while (n) { if (n % 2) { p = mul(p, a, mod_); } n >>= 1; a = mul(a, a, mod_); } return p % mod_; } long long int powi(long long int a, long long int mod_) { return powm(a, mod_ - 2, mod_); } double dist(pair<pair<double, double>, double> a, pair<pair<double, double>, double> b) { double d = (a.first.first - b.first.first) * (a.first.first - b.first.first) + (a.first.second - b.first.second) * (a.first.second - b.first.second) + (a.second - b.second) * (a.second - b.second); d = sqrtl(d); return d; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cout << setprecision(15); long long int mn, mx; long long int n, m, t, k, i, j, sum = 0, flag = 0, cnt = 0; long long int x = 0, y = 0, z, l, r, q; int TC = 1; while (TC--) { cin >> n; std::vector<pair<pair<double, double>, double>> a(n); for (i = 0; i < n; ++i) { cin >> a[i].first.first >> a[i].first.second >> a[i].second; } double dis[n][n]; dis[0][0] = 0.0; for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { dis[i][j] = dist(a[i], a[j]); } } double mn = 2e18; for (i = 1; i < n; ++i) { for (j = i + 1; j < n; ++j) { double x = (dis[i][j] + dis[0][i] - dis[0][j]) / 2.0; double y = (dis[i][j] - dis[0][i] + dis[0][j]) / 2.0; if (x >= 0.0 and x <= dis[i][j] and y >= 0.0 and y <= dis[i][j]) { if (dis[0][j] + x < mn) mn = dis[0][j] + x; } } } cout << mn; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; struct Point { int x, y, z; } P[MAXN]; int N; double D[MAXN]; double dist(const Point& p, const Point& q) { int dx = p.x - q.x; int dy = p.y - q.y; int dz = p.z - q.z; return sqrt(dx * dx + dy * dy + dz * dz); } int main() { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d%d%d", &P[i].x, &P[i].y, &P[i].z); } for (int i = 1; i < N; i++) { D[i] = dist(P[i], P[0]); } double ret = 1e9; for (int i = 1; i < N; i++) { for (int j = i + 1; j < N; j++) { ret = min(ret, 0.5 * (D[i] + D[j] + dist(P[i], P[j]))); } } printf("%.10f\n", ret); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1E9 + 7; const int INF = (int)2E9; const long long INFLL = (long long)2E18; const double INFD = 2E9; const double EPS = 1E-9; const double PI = acos(-1.0); double dist(pair<double, pair<double, double> > A, pair<double, pair<double, double> > B) { double x = A.first - B.first, y = A.second.first - B.second.first, z = A.second.second - B.second.second; x *= x; y *= y; z *= z; return sqrt(x + y + z); } int n; pair<double, pair<double, double> > P[5010]; double D[5010][5010]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lf%lf%lf", &P[i].first, &P[i].second.first, &P[i].second.second); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) D[i][j] = dist(P[i], P[j]); double ans = INFD; for (int i = 0; i < n; i++) { if (i == 0) continue; for (int j = 0; j < n; j++) { if (j == 0) continue; if (j == i) continue; ans = min(ans, (D[0][i] + D[i][j] + D[j][0]) / 2); } } printf("%.9lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z; point() {} }; double dis(point A, point B) { return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2) + pow(A.z - B.z, 2)); } double per(point A, point B, point C) { return dis(A, B) + dis(B, C) + dis(C, A); } point p[5000]; int main() { int n, i, k; double ret = 1000000000; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].z); for (i = 1; i < n - 1; i++) for (k = i + 1; k < n; k++) ret = min(ret, 0.5 * per(p[0], p[i], p[k])); printf("%.10lf", ret); return 0; }
#include <bits/stdc++.h> using namespace std; long double SQR(long double x) { return x * x; } struct point { int x, y, z; void read() { scanf("%d%d%d", &x, &y, &z); } double dist(point b) { return sqrt(SQR(x - b.x) + SQR(y - b.y) + SQR(z - b.z)); } } a[5050]; int n; long double ans = 1e100, t1, t2, t3, now; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) a[i].read(); for (int i = 1; i < n; ++i) { t1 = a[0].dist(a[i]); for (int j = i + 1; j < n; ++j) { t2 = a[0].dist(a[j]); t3 = a[i].dist(a[j]); now = (t1 + t2 + t3) / 2; if (now < ans) ans = now; } } cout.precision(12); cout << fixed << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct points { double x, y, z; } p[5005]; double dist(int i, int j) { return sqrt((p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y) + (p[i].z - p[j].z) * (p[i].z - p[j].z)); } int main() { int n = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z); } double res = -1; for (int i = 2; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { double tmp = dist(1, i) + dist(1, j) + dist(i, j); if (res == -1) { res = tmp; } else { res = min(res, tmp); } } } res /= 2.0; printf("%.8lf\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; int x[5001], y[5001], z[5001]; double dist(double x, double y, double z) { return sqrt(x * x + y * y + z * z); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d%d", x + i, y + i, z + i); } double menor = 1000000000.0; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { double temp = dist(x[i] - x[0], y[i] - y[0], z[i] - z[0]) + dist(x[j] - x[0], y[j] - y[0], z[j] - z[0]) + dist(x[j] - x[i], y[j] - y[i], z[j] - z[i]); if (temp < menor) { menor = temp; } } } printf("%.10f\n", menor / 2); }
#include <bits/stdc++.h> using namespace std; double t = 1e9, x[5005], y[5005], z[5005]; double L(int i, int j) { return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])); } int main() { int n, i, j; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%lf %lf %lf", &x[i], &y[i], &z[i]); for (i = 2; i <= n; i++) for (j = 2; j < i; j++) t = min(t, L(1, j) + L(1, i) + L(i, j)); return printf("%.10lf\n", t / 2), 0; }
#include <bits/stdc++.h> using namespace std; struct node { double a, b, c; }; double max(double a, double b) { return a < b ? b : a; } double min(double a, double b) { return a > b ? b : a; } node tm[5005]; double one_2[5005]; const double inf = 2147483647.0; int main() { double a, b, c; int n; int i, j; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%lf%lf%lf", &tm[i].a, &tm[i].b, &tm[i].c); } double a1 = tm[1].a; double b1 = tm[1].b; double c1 = tm[1].c; double dis_pow2; for (j = 2; j <= n; j++) { double a2 = tm[j].a; double b2 = tm[j].b; double c2 = tm[j].c; dis_pow2 = sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2) + (c1 - c2) * (c1 - c2)); one_2[j] = dis_pow2; } double ans = inf; int id; double dis2; for (id = 2; id <= n; id++) { double dis1 = one_2[id]; a1 = tm[id].a; b1 = tm[id].b; c1 = tm[id].c; for (j = 2; j <= n; j++) { if (j == id) continue; double a2 = tm[j].a; double b2 = tm[j].b; double c2 = tm[j].c; dis2 = sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2) + (c1 - c2) * (c1 - c2)); double cha = fabs(dis1 - one_2[j]); ans = min(ans, dis1 + (cha + dis2) / 2); } } printf("%.7lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 5050; double x[MAXN], y[MAXN], z[MAXN], r[MAXN]; inline double sqr(double x) { return x * x; } int main() { int n; double ans; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); r[i] = sqrt(sqr(x[i] - x[0]) + sqr(y[i] - y[0]) + sqr(z[i] - z[0])); } ans = 1e100; for (int i = 1; i < n; ++i) { for (int j = 1; j < i; ++j) { ans = min(ans, r[i] + r[j] + sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j]))); } } printf("%.10lf\n", ans / 2); return 0; }
#include <bits/stdc++.h> const int N = 5005; double ans = 1e99; double x[N], y[N], z[N]; int n; double D(int i, int j) { return sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j]))); } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); for (int j = 2; j <= n; ++j) for (int k = j + 1; k <= n; ++k) { double cur = D(1, j) + D(j, k) + D(1, k); if (cur < ans) ans = cur; } printf("%0.8lf\n", ans / 2); }
#include <bits/stdc++.h> using namespace std; const double INF = 1000000000; struct point { double x, y, z; }; double length(point a, point b) { double ans = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); return ans; } double per(point a, point b, point c) { double ans = length(a, b) + length(b, c) + length(a, c); return ans; } int main() { int n; cin >> n; point arr[5000]; for (int i = 0; i < n; i++) cin >> arr[i].x >> arr[i].y >> arr[i].z; double min = INF; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) if (per(arr[0], arr[i], arr[j]) < min) min = per(arr[0], arr[i], arr[j]); printf("%.9lf", min / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int n, x[5010], y[5010], z[5010]; double Dis(int i, int j) { return sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j]))); } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; } double ans = 1e9; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = min(ans, (Dis(0, i) + Dis(0, j) + Dis(j, i)) / 2); } } cout << fixed << setprecision(6) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z; } P[5005]; int N; double sqr(double x) { return x * x; } int isqr(int x) { return x * x; } double dist(point A, point B) { return sqrt(sqr((double)A.x - B.x) + sqr((double)A.y - B.y) + sqr((double)A.z - B.z)); } int idist(point A, point B) { return isqr(A.x - B.x) + isqr(A.y - B.y) + isqr(A.z - B.z); } int main() { cin >> N; for (int i = 1; i <= N; ++i) cin >> P[i].x >> P[i].y >> P[i].z; double ans = 1e12; for (int i = 2; i < N; ++i) for (int j = i + 1; j <= N; ++j) { double d = 0.5 * (dist(P[i], P[1]) + dist(P[j], P[1]) + dist(P[i], P[j])); ans = min(ans, d); } printf("%lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double point[5000][3]; double mine(double x, double y) { return ((x < y) ? x : y); } double dis(double x, double y, double z, double a, double b, double c) { return (sqrt((x - a) * (x - a) + (y - b) * (y - b) + (z - c) * (z - c))); } int main() { double n, min = 10000000; double ans = 10000000; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) cin >> point[i][j]; } for (int i = 0; i < 1; i++) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { ans = mine(ans, (dis(point[i][0], point[i][1], point[i][2], point[j][0], point[j][1], point[j][2]) + dis(point[j][0], point[j][1], point[j][2], point[k][0], point[k][1], point[k][2]) + dis(point[i][0], point[i][1], point[i][2], point[k][0], point[k][1], point[k][2]))); } } } printf("%.9f", ans / 2.0); }
#include <bits/stdc++.h> using namespace std; const int inf = 99999; double m = inf; int n, i, j, a[5001], b[5001], c[5001]; double d; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; for (i = 2; i <= n - 1; i++) for (j = i + 1; j <= n; j++) { d = sqrt((a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]) + (c[i] - c[j]) * (c[i] - c[j])); d += sqrt((a[i] - a[1]) * (a[i] - a[1]) + (b[i] - b[1]) * (b[i] - b[1]) + (c[i] - c[1]) * (c[i] - c[1])); d += sqrt((a[1] - a[j]) * (a[1] - a[j]) + (b[1] - b[j]) * (b[1] - b[j]) + (c[1] - c[j]) * (c[1] - c[j])); if (m > d) m = d; } printf("%5f", m / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int x[5000]; int y[5000]; int z[5000]; double dist[5000]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; double ret = 1e18; for (int i = 1; i < n; i++) { int xx = x[i] - x[0]; int yy = y[i] - y[0]; int zz = z[i] - z[0]; dist[i] = sqrt(xx * xx + yy * yy + zz * zz); } for (int i = 1; i < n; i++) { for (int j = 1; j < i; j++) { double a = dist[i]; double b = dist[j]; int xx = x[i] - x[j]; int yy = y[i] - y[j]; int zz = z[i] - z[j]; double d = sqrt(xx * xx + yy * yy + zz * zz); if (a > b) swap(a, b); double take = b - a; a += take; d -= take; ret = min(ret, a + d / 2); } } cout << fixed << setprecision(12) << ret << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; struct Point { double x, y, z; }; double dist(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } Point p[MAXN]; double dis[MAXN]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z); for (int i = 1; i < n; i++) dis[i] = dist(p[0], p[i]); double ta = 100000.0; for (int i = 1; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { double tmp = dist(p[j], p[i]); double td; if (dis[i] > dis[j]) td = (tmp - dis[i] + dis[j]) / 2 + dis[i]; else td = (tmp - dis[j] + dis[i]) / 2 + dis[j]; if (ta > td) ta = td; } } printf("%.6lf\n", ta); } return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z; }; point P[50001]; double dist(point &A, point &B) { return sqrt(((A.x - B.x) * (A.x - B.x)) + ((A.y - B.y) * (A.y - B.y)) + ((A.z - B.z) * (A.z - B.z))); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf("%d %d %d", &P[i].x, &P[i].y, &P[i].z); double mn = 10E40; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != 0 && j != 0 && i != j) { double d = dist(P[0], P[i]) + dist(P[0], P[j]) + dist(P[i], P[j]); mn = min(mn, d); } printf("%.10lf\n", mn / 2.); return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { int x, y, z; }; Point a[5100]; double dis(Point a, Point b) { return sqrt(((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)) * 1.0); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z); } double min = 100000000; for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { if (i == j) continue; else { if ((dis(a[i], a[j]) + dis(a[i], a[0]) + dis(a[j], a[0])) < min) { min = dis(a[i], a[j]) + dis(a[i], a[0]) + dis(a[j], a[0]); } } } } printf("%.10lf\n", min / 2); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, i, j, k; cin >> n; vector<long double> x(n), y(n), z(n), t(n); long double d, ans = 1E30, tt; for (i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; if (i > 0) { t[i] = sqrt((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0]) + (z[i] - z[0]) * (z[i] - z[0])); } } for (i = 1; i < n; i++) { for (j = i + 1; j < n; j++) { d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])); tt = (d - abs(t[i] - t[j])) / 2.0 + max(t[i], t[j]); ans = min(ans, tt); } } cout << setprecision(10) << fixed << ans << "\n"; return 0; }