fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. vector<int> c ( 10e6+1, 0);
  6. vector<int> numbers;
  7. vector<int> indices;
  8.  
  9. int main(){
  10.  
  11. int total = 0;
  12. int n;
  13. cin >> n;
  14.  
  15. int temp;
  16.  
  17. for(int i =0; i < n; i++){
  18. cin >> temp;
  19. numbers.push_back(temp);
  20. total+=temp;
  21. c[temp]++;
  22. }
  23.  
  24.  
  25. for(int i =0; i < numbers.size(); i++){
  26. c[numbers[i]]--;
  27. if((total - numbers[i]) % 2 == 0){
  28. temp = total-numbers[i];
  29. temp/=2;
  30.  
  31. if(c[temp] > 0) indices.push_back(i);
  32. }
  33. c[numbers[i]]++;
  34. }
  35.  
  36. cout << indices.size() << endl;
  37.  
  38. for(int i =0; i < indices.size(); i++){
  39. cout << (indices[i] + 1 ) << " ";
  40. }
  41. cout << endl;
  42.  
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 15240KB
stdin
4
8 3 5 2
stdout
2
1 4