fork download
  1. #include <cstdio>
  2. #include <set>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. int N;
  8. scanf(" %d",&N);
  9. vector<int> post(N);
  10. for(int i =0; i < N; i++) scanf(" %d",&post[i]);
  11. set<int> boli;
  12. int i1,i2,i3 =-1;
  13. for(int i =N-1; i >= 0; i--) {
  14. for(set<int>::iterator it =boli.begin(); it != boli.end(); it++) {
  15. if(*it+*boli.begin()+post[i] > 0) break; // nemusim pozerat zvysne sucty
  16. if(boli.find(-post[i]-*it) != boli.end()) {i1 =i; break;}}
  17. boli.insert(post[i]);}
  18. for(int i =i1+1; i < N; i++) {
  19. for(int j =i+1; j < N; j++) if(post[i1]+post[j]+post[i] == 0) {i3 =j; i2 =i; break;}
  20. if(i3 != -1) break;}
  21. printf("%d %d %d\n",i1+1,i2+1,i3+1);
  22. return 0;}
Success #stdin #stdout 0s 2964KB
stdin
6
7 -1 3 4 -2 -1
stdout
2 3 5