QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295570#5076. Prof. Pang and Antszzuqy#WA 29ms3820kbC++14744b2023-12-31 13:50:252023-12-31 13:50:26

Judging History

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

  • [2023-12-31 13:50:26]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:3820kb
  • [2023-12-31 13:50:25]
  • 提交

answer

#include <bits/stdc++.h>
#define N 1000009
#define int long long
using namespace std;
int n, m, a[N];

bool ok(int mid) {
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		int tmp = mid - 2 * a[i] - 1;
		if (tmp <= 0)
			continue;
		if (tmp >= a[i] + 1)
			sum += mid / 2;
		else
			sum += tmp;
		if (sum >= m)
			return 1;
	}
	return 0;
}

void solve() {
	scanf("%lld%lld", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	int l = 0, r = 1000000000000000000, ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (ok(mid))
			ans = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	printf("%lld\n", ans);
}

signed main() {
	int t;
	scanf("%lld", &t);
	while (t--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

input:

3
2 4
1 2
3 10
1 2 3
5 1
1 2 3 4 5

output:

6
9
4

result:

ok 3 number(s): "6 9 4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1
1 100000000000000
1000000000

output:

200000000000000

result:

ok 1 number(s): "200000000000000"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

1
10 1
1 1 1 1 1 1 1 1 1 1

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 29ms
memory: 3616kb

input:

100000
1 76
95
1 60
68
1 81
86
1 88
67
1 69
28
1 75
65
1 56
22
1 88
60
1 51
41
1 64
11
1 54
71
1 63
19
1 88
5
1 89
66
1 80
66
1 81
48
1 67
99
1 94
36
1 54
46
1 51
37
1 82
17
1 74
41
1 69
61
1 79
65
1 78
10
1 71
17
1 87
88
1 83
2
1 58
29
1 59
43
1 78
53
1 75
73
1 77
71
1 52
82
1 63
69
1 83
19
1 61
27...

output:

267
197
254
203
138
197
112
182
125
128
197
126
176
200
200
162
266
188
140
113
164
148
185
197
156
142
264
166
116
131
161
221
215
217
202
166
122
162
250
203
140
137
220
132
108
192
198
275
224
197
204
140
146
185
122
142
176
257
269
188
144
246
251
194
212
184
192
136
234
128
190
242
254
143
152
...

result:

wrong answer 4th numbers differ - expected: '223', found: '203'