diff --git a/medium/day_5/solution.cpp b/medium/day_5/solution.cpp index 2eaac7b..28b0c02 100644 --- a/medium/day_5/solution.cpp +++ b/medium/day_5/solution.cpp @@ -1,31 +1,50 @@ -//Write your code here -#include +// Write your code here +#include using namespace std; #define int long long -int32_t main(){ - int n , sum=0; - cin>>n; - vector a(n) , ans; - for(int i=0; i>a[i]; sum += a[i];} - for(int i=0; i> n; + vector a(n), ans; + vector> vp; + for (int i = 0; i < n; i++) + { + cin >> a[i]; + sum += a[i]; + vp.push_back({a[i], i}); + } + if (n <= 2) + { + cout << 0 << endl; + } + else + { + sort(vp.begin(), vp.end()); + for (int i = 0; i < n; i++) + { + if (i != n - 1) + { + int k = sum - vp[i].first; + if (2 * vp[n - 1].first == k) + ans.push_back(vp[i].second + 1); + } + else + { + int k = sum - vp[i].first; + if (2 * vp[n - 2].first == k) + ans.push_back(vp[i].second + 1); } } - } - if(ans.size()){ - cout<