ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282 | #5. 「WyOJ Round 1」炽 · 踏浪而歌 | xxxbt | 40 | 1446ms | 8480kb | C++23 | 1.6kb | 2025-04-18 15:48:18 | 2025-04-18 18:04:19 |
answer
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 1e5 + 10;
int a[kMaxN], n;
vector<pair<int, int>> ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int k = max((accumulate(a, a + n, 0) + 1) / 2, *max_element(a, a + n));
for (int m = k, t = k; t--;) {
int flag = 0;
pair<int, int> num;
for (int i = 1; i <= n; i++) {
if (a[i - 1] > 0) {
for (int j = i + 1; j <= n; j++) {
if (a[j - 1] > 0) {
a[i - 1]--, a[j - 1]--;
int w = *max_element(a, a + n);
a[i - 1]++, a[j - 1]++;
if (w <= (m - 1)) {
num = {i, j}, flag = 1;
break;
}
}
}
if (flag) break;
}
}
if (!flag) {
for (int i = 1; i <= n; i++) {
if (a[i - 1] > 0) {
a[i - 1]--;
int w = *max_element(a, a + n);
a[i - 1]++;
if (w <= (m - 1)) {
num = {i, i}, flag = 1;
break;
}
}
}
}
if (flag) {
ans.push_back(num), a[num.first - 1]--;
if (num.first != num.second) {
a[num.second - 1]--;
}
m--;
} else {
int val = *max_element(a, a + n), p = 1;
for (int i = 0; i < n; ++i) {
if (a[i] == val) {
p = i + 1;
break;
}
}
ans.emplace_back(p, p), a[p - 1]--, m--;
}
}
cout << k << '\n';
for (pair<int, int> i : ans) {
cout << i.first << ' ' << i.second << '\n';
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 3612kb
input:
6 3 4 1 2 4 6
output:
10 1 2 1 2 1 2 2 3 4 6 4 6 5 6 5 6 5 6 5 6
result:
ok 21 numbers
Test #2:
score: 0
Wrong Answer
time: 393ms
memory: 4960kb
input:
1000 1000 1000 1000 999 996 993 991 991 991 991 991 991 988 988 988 988 987 984 980 980 978 978 977 ...
output:
259517 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
result:
wrong answer 3rd numbers differ - expected: '1', found: '2'
Test #3:
score: 10
Accepted
time: 88ms
memory: 8480kb
input:
5 93761 154479 466694 134030 151036
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
result:
ok 1000001 numbers
Test #4:
score: 0
Time Limit Exceeded
input:
56700 20 9 3 26 6 14 11 26 15 4 7 7 18 3 55 16 0 2 71 8 21 3 15 21 2 25 38 10 2 15 3 1 3 15 6 2 26 5...
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
18574 19 245 80 2 53 157 18 27 35 19 109 14 30 97 26 10 5 22 142 102 13 114 67 70 142 131 10 177 18 ...
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
36045 6 62 19 5 21 38 42 13 52 3 10 4 14 65 24 15 9 21 19 24 1 3 2 59 2 19 80 28 9 39 49 26 20 20 14...
output:
result:
Test #7:
score: 10
Accepted
time: 191ms
memory: 8172kb
input:
100 442 37503 827 703 10394 1215 23599 313 1705 10819 6152 89 341 3448 778 7153 20397 5166 2735 2100...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
result:
ok 1000001 numbers
Test #8:
score: 10
Accepted
time: 773ms
memory: 8360kb
input:
1000 6 436 820 182 327 3272 993 1042 321 2717 69 4321 706 4565 1280 528 1632 1317 916 125 262 1712 6...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2...
result:
ok 1000001 numbers
Test #9:
score: 0
Time Limit Exceeded
input:
10000 6 107 38 107 3 28 89 15 30 19 89 2 435 75 45 55 119 125 15 42 101 83 9 134 3 278 292 55 255 2 ...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
100000 3 3 62 19 5 21 0 17 21 2 1 36 3 11 2 3 10 22 17 3 10 0 4 3 11 20 11 22 12 12 12 1 10 4 9 6 4 ...