fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n; cin >> n;
  6. vector<int> arr(n);
  7. for(int i = 0; i < n; i++)
  8. cin >> arr[i];
  9.  
  10. unordered_map<int,vector<pair<int,int>>> mp;
  11. vector<vector<int>> res;
  12. for(int k = 2; k < n-1; k++){
  13. int j = k-1;
  14. for(int i = 0; i < j; i++){
  15. int sum = arr[i]+arr[j];
  16. mp[sum].push_back({i,j});
  17. }
  18. for(int l = k+1; l < n; l++){
  19. int target = -1*(arr[k]+arr[l]);
  20. if(mp.find(target)!=mp.end()){
  21. vector<pair<int,int>> temp = mp[target];
  22. for(int x = 0; x < temp.size(); x++){
  23. cout << temp[x].first << " " << temp[x].second << " " << k << " " << l << endl;
  24. }
  25. }
  26. }}
  27.  
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5316KB
stdin
7
1 2 3 4 -1 -2 -2
stdout
0 1 4 5
0 1 4 6
0 2 5 6