You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
754 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main() {
multiset<int> S;
int n, m;
while (~scanf("%d", &m)) {
n = sqrt(8 * m + 1) / 2;
S.clear();
for (int i = 0, x; i < m; i++) scanf("%d", &x), S.insert(x);
vector<int> ans(n);
for (int i = 0; i < n; i++) {
ans[i] = *S.begin();
for (int j = 0; j < i; j++)
S.erase(S.find(ans[j] + ans[i]));
S.erase(S.find(ans[i]));
}
printf("%d\n", n);
for (int i = 0; i < ans.size(); i++)
printf("%d%c", ans[i], " \n"[i == ans.size() - 1]);
}
return 0;
}