Created
November 16, 2018 16:22
-
-
Save tabvn/00eb93a6dbd0e92f9345a3afb205d0f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
vector<long int> v; | |
vector<long int> result; | |
bool descSort(long int a, long int b){ | |
return a > b; | |
} | |
long long totalSum(){ | |
long long value = 0; | |
for (long long i = 0; i < v.size(); ++i){ | |
value += v[i]; | |
} | |
return value; | |
} | |
void findSubArr(long long value){ | |
long long subTotal; | |
for (long long i = 0; i < v.size(); ++i){ | |
subTotal = value - v[i]; | |
for (long long j = 0; j < v.size(); ++j){ | |
if(j == i){ | |
continue; | |
} | |
if(subTotal - v[j] == v[i]){ | |
// bo vi tri nay ok | |
result.push_back(j); | |
} | |
} | |
} | |
cout << result.size() << endl; | |
for (long long i = 0; i < result.size(); ++i){ | |
cout << (result[i] +1) << " "; | |
} | |
} | |
int main(){ | |
long long n; | |
long int a; | |
cin >> n; | |
for (long long i = 0; i < n; ++i){ | |
cin >> a; | |
v.push_back(a); | |
} | |
//sort(v.begin(), v.end(), descSort); | |
findSubArr(totalSum()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment