Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
38631 沈仲恩 【J】T1 C++ 运行出错 0 0 MS 256 KB 1695 2025-10-18 13:55:44

Tests(0/25):


#include <bits/stdc++.h> #define int long long using namespace std; int n, c; int a[100005], b[100005]; inline int calc(int x) { int y = c - x; int cur = 0; for (int i = 1; i <= n; i++) { cur += (a[i] - x) * (b[i] - y); } return cur; } signed main() { freopen("max.in", "r", stdin); freopen("max.out", "w", stdout); scanf("%lld %lld", &n, &c); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int i = 1; i <= n; i++) { scanf("%lld", &b[i]); } if (n <= 100) { int ax = 0, ay = c, as = calc(0); for (int x = -1000; x <= 1000; x++) { int y = c - x; int cur = 0; for (int i = 1; i <= n; i++) { cur += (a[i] - x) * (b[i] - y); } if (cur > as) { as = cur; ax = x; ay = y; } } printf("%lld %lld", ax, ay); return 0; } int l = -1e9, r = 1e9; while (r - l > 1000) { int m1 = l + (r - l) / 3; int m2 = r - (r - l) / 3; int v1 = calc(m1), v2 = calc(m2); while (v1 == v2) { m2++; v2 = calc(m2); } if (v1 < v2) { l = m1; } else r = m2; } int ax = l, ay = c - l, as = calc(l); for (int x = l + 1; x <= r; x++) { int cur = calc(x); if (cur > as) { as = cur; ax = x, ay = c - x; } } printf("%lld %lld", ax, ay); return 0; }


测评信息: