Advertisement
Josif_tepe

Untitled

Mar 24th, 2023
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <vector>
  5.  
  6. using namespace std;
  7. typedef long long ll;
  8. int main()
  9. {
  10.     int n;
  11.     cin >> n;
  12.     vector<ll> v(n);
  13.     map<ll, vector<int>> mapa;
  14.     ll sum = 0, result = 0;
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> v[i];
  17.         sum += v[i];
  18.         mapa[sum].push_back(i);
  19.     }
  20.     sum = 0;
  21.     for(int i = n - 1; i >= 0; i--) {
  22.         sum += v[i];
  23.         if(mapa.count(sum)) {
  24.             if(mapa[sum][0] < i) {
  25.                 result = max(result, sum);
  26.             }
  27.         }
  28.     }
  29.     cout << result << endl;
  30.         return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement