Submission #73092363
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
if (n & 1) cout << a[n - 1] << '\n';
else {
i64 sum = accumulate(a.begin(), a.end(), 0LL);
int m = n / 2;
vector<int> ans;
// all 2
if (sum % m == 0) ans.push_back(sum / m);
// some 1
int p = n - 1;
while (p - 1 >= 0 && a[p - 1] == a[p]) p--;
bool ok = true;
int l = 0, r = p - 1;
while (l < r) {
if ((i64) a[l] + a[r] != a[n - 1]) {
ok = false;
break;
}
l++, r--;
}
if (ok && l > r) ans.push_back(a[n - 1]);
int sz = ans.size();
sort(ans.begin(), ans.end());
for (int i = 0; i < sz; i++) cout << ans[i] << " \n"[i == sz - 1];
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - AtCoder Riko |
| User | liangsheng |
| Language | C++23 (GCC 15.2.0) |
| Score | 350 |
| Code Size | 1120 Byte |
| Status | AC |
| Exec Time | 29 ms |
| Memory | 4680 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt |
| All | 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt, 1_1.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 2_1.txt, 2_2.txt, 2_3.txt, 2_4.txt, 3_1.txt, 3_2.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 4_1.txt, 4_2.txt, 4_3.txt, 4_4.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 0_sample_1.txt | AC | 1 ms | 3576 KiB |
| 0_sample_2.txt | AC | 1 ms | 3572 KiB |
| 0_sample_3.txt | AC | 1 ms | 3556 KiB |
| 1_1.txt | AC | 26 ms | 4516 KiB |
| 1_2.txt | AC | 25 ms | 4596 KiB |
| 1_3.txt | AC | 24 ms | 4600 KiB |
| 1_4.txt | AC | 25 ms | 4636 KiB |
| 1_5.txt | AC | 25 ms | 4616 KiB |
| 2_1.txt | AC | 29 ms | 4596 KiB |
| 2_2.txt | AC | 29 ms | 4608 KiB |
| 2_3.txt | AC | 28 ms | 4516 KiB |
| 2_4.txt | AC | 28 ms | 4680 KiB |
| 3_1.txt | AC | 29 ms | 4636 KiB |
| 3_2.txt | AC | 29 ms | 4572 KiB |
| 3_3.txt | AC | 28 ms | 4680 KiB |
| 3_4.txt | AC | 17 ms | 4516 KiB |
| 3_5.txt | AC | 1 ms | 3500 KiB |
| 3_6.txt | AC | 24 ms | 4556 KiB |
| 4_1.txt | AC | 9 ms | 4556 KiB |
| 4_2.txt | AC | 14 ms | 4556 KiB |
| 4_3.txt | AC | 1 ms | 3616 KiB |
| 4_4.txt | AC | 1 ms | 3596 KiB |