QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131830#5125. Adjusted Averagemshcherba#TL 0ms0kbC++171.6kb2023-07-28 14:59:052023-07-28 14:59:07

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-28 14:59:07]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-07-28 14:59:05]
  • 提交

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;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

5 2 2
1 2 3 100 200

output:


result: