fork download
  1. //#include <ext/pb_ds/assoc_container.hpp>
  2. //#include <ext/pb_ds/tree_policy.hpp>
  3. //using namespace __gnu_pbds;
  4. //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. //#define int long long
  8. #define dd double
  9. #define ld long double
  10. #define ull unsigned long long
  11. #define yes cout << "YES\n"
  12. #define no cout << "NO\n"
  13. #define el "\n"
  14. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  15. #define fix(x) cout << fixed << setprecision(x)
  16. #define all(v) v.begin(),v.end()
  17. void file()
  18. {
  19. #ifndef ONLINE_JUDGE
  20. freopen("input.txt", "r", stdin);
  21. freopen("output.txt", "w", stdout);
  22. #endif
  23. }
  24. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  25. int lcm(int a, int b) { return a / gcd(a, b) * b; }
  26. bool prime(int n) {
  27. if (n == 2) return true;
  28. if (n % 2 == 0 || n == 1) return false;
  29. for (int i = 3; i * i <= n; i += 2)
  30. if (n % i == 0) return false;
  31. return true;
  32. }
  33. //Here We Go Again
  34. int32_t main()
  35. {
  36. Arwa
  37. int t=1;
  38. //cin>>t;
  39. while(t--)
  40. {
  41. int n;
  42. cin>>n;
  43. int arr[n];
  44. map<int,int>m1,m2;
  45. for(int i=0;i<n;i++)
  46. cin>>arr[i];
  47. int sum1=0,sum2=0,mx=LONG_LONG_MIN;
  48. m1[0]=-1,m2[0]=n;
  49. for(int i=0;i<n;i++)
  50. {
  51. sum1+=arr[i];
  52. m1[sum1]=i;
  53. }
  54. for(int i=n-1;i>=0;i--)
  55. {
  56. sum2+=arr[i];
  57. m2[sum2]=i;
  58. }
  59. for(auto it:m1)
  60. {
  61. if(m2[it.first]&&it.second<m2[it.first])
  62. mx=max(mx,it.first);
  63. }
  64. cout<<max(mx,0)<<el;
  65. }
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0