voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, mi = LONG_LONG_MAX; cin >> n; vector<pair<int, int>> data(n); for (int i = 0; i < n; ++i) { int m, tmp; cin >> m; int u = LONG_LONG_MAX, v = LONG_LONG_MAX; for (int j = 0; j < m; ++j) { cin >> tmp; mi = min(mi, tmp); if (tmp < u) { v = u; u = tmp; } elseif (tmp < v) v = tmp; } data[i] = {u, v}; } int t = 0; for (int i = 0; i < n; ++i) { int cur = (data[i].second - data[i].first) + (data[i].first - mi); int lst = (data[t].second - data[t].first) + (data[t].first - mi); if (cur < lst) t = i; } int ans = 0; for (int i = 0; i < n; ++i) { if (i == t) ans += mi; else ans += data[i].second; } cout << ans << endl; } }
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n; cin >> n;
int ans = 0; auto cal = [&](int mx) { int total = 0, big = 0; set<int> s; for (int i = 1; i <= n; ++i) s.insert(i); for (int i = n; i > 0; --i) { int mi = mx / i; auto iter = s.upper_bound(mi); if (iter == s.begin()) return; iter--; total += *iter * i; big = max(big, *iter * i); s.erase(iter); } ans = max(ans, total - big); };
int mi = ((n + 1) / 2) * ((n + 2) / 2); for (int i = 1; i <= n; ++i) { for (int j = (mi + i - 1) / i; j <= n; ++j) { int maxValue = i * j; cal(maxValue); } } cout << ans << endl; } }