fork download
  1. #include <cstdio>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. const int N = 1e6 + 3;
  7.  
  8. unordered_map <int, int> M[N];
  9. int n, a[N], mx = 0;
  10.  
  11. int main (){
  12. ios_base::sync_with_stdio(0);
  13. cin.tie(0);
  14. cout.tie(0);
  15. cin >> n;
  16. for (int i = 0; i < n; ++i){
  17. cin >> a[i];
  18. M[i].reserve(i);
  19. M[i].max_load_factor(0.25);
  20. }
  21. for (int i = 1; i < n; ++i){
  22. for (int j = 0; j < i; ++j){
  23. int x = a[i] - a[j];
  24. if (M[j].find(-x) != M[j].end()) {
  25. int w = M[j].count(-x) + 1;
  26. M[i][x] = w;
  27. mx = max(mx, w);
  28. }
  29. else{
  30. M[i][x] = 1;
  31. mx = max(mx, 1);
  32. }
  33. }
  34. }
  35. cout << mx + 1;
  36. return 0;
  37. }
Success #stdin #stdout 0.02s 58228KB
stdin
Standard input is empty
stdout
1