QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#131830 | #5125. Adjusted Average | mshcherba# | TL | 0ms | 0kb | C++17 | 1.6kb | 2023-07-28 14:59:05 | 2023-07-28 14:59:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
int n, k;
LL x;
cin >> n >> k >> x;
vector<int> a(n);
for (int& ai : a) {
cin >> ai;
}
mt19937 rng;
vector<LL> vec[2][3];
double ans = 1e18;
while ((double)clock() / CLOCKS_PER_SEC < 7) {
shuffle(ALL(a), rng);
FOR(j, 0, 2) {
int l = j == 0 ? 0 : n / 2, r = j == 0 ? n / 2 : n;
LL s = accumulate(a.begin() + l, a.begin() + r, 0LL);
FOR(m, 0, 3) {
vec[j][m].clear();
}
vec[j][0] = {s};
FOR(i1, l, r) {
vec[j][1].push_back(s - a[i1]);
FOR(i2, i1 + 1, r) {
vec[j][2].push_back(s - a[i1] - a[i2]);
}
}
}
FOR(j, 0, 2) {
FOR(m, 0, 3) {
sort(ALL(vec[j][m]));
}
}
FOR(k1, 0, 3) {
FOR(k2, 0, min(3, k + 1 - k1)) {
LL y = x * (n - k1 - k2);
int ptr = SZ(vec[1][k2]) - 1;
for (LL x1 : vec[0][k1]) {
while (ptr > 0 && x1 + vec[1][k2][ptr - 1] >= y) {
ptr--;
}
FOR(p, max(0, ptr - 1), ptr + 1) {
ans = min(ans, abs((double)(x1 + vec[1][k2][p]) / (n - k1 - k2) - x));
}
}
}
}
}
cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
5 2 2 1 2 3 100 200