Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int main()
- {
- int n;
- cin >> n;
- vector<ll> v(n);
- map<ll, vector<int>> mapa;
- ll sum = 0, result = 0;
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- sum += v[i];
- mapa[sum].push_back(i);
- }
- sum = 0;
- for(int i = n - 1; i >= 0; i--) {
- sum += v[i];
- if(mapa.count(sum)) {
- if(mapa[sum][0] < i) {
- result = max(result, sum);
- }
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement