fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <algorithm>
  4. using namespace std;
  5. typedef long long int LLI;
  6.  
  7. int main() {
  8. int N;
  9. cin >> N;
  10. unordered_set<LLI> s, n;
  11. LLI list[1000];
  12. for (int i = 0; i < N; i++) {
  13. cin >> list[i];
  14. n.emplace(list[i]);
  15. }
  16. // 두 개의 합을 미리 저장한 후 그걸 순회하며 탐색
  17. sort(list, list + N);
  18. for (int i = 0; i < N; i++) {
  19. for (int j = i; j < N; j++) {
  20. s.emplace(list[i] + list[j]);
  21. }
  22. }
  23. for (int i=N-1; i>=0; i--) {
  24. // list[i] = n? + s?
  25. for (int j = i-1; j>=0; j--) {
  26. LLI t = list[i];
  27. if (s.count(t - list[j])) {
  28. cout << t;
  29. return 0;
  30. }
  31. }
  32. }
  33. }
  34.  
Success #stdin #stdout 0.01s 5296KB
stdin
5
2
4
5
12
13
stdout
13