Language: C++


#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n;
ll a[100010];
char op[100010];
char buf[8];
ll left=0,right=0,ans=-2e11;

int main() {
    scanf("%d",&n);
    scanf("%lld",&a[0]);
    left=a[0];
    for (int i=1;i<n;i++) {
        scanf("%s",buf);
        scanf("%lld",a+i);
        op[i]=buf[0];
        right+=a[i];
    }
    int idx=1;
    while (idx<n&&op[idx]=='+') {
        left+=a[idx];
        right-=a[idx];
        idx++;
    }
    ll tmp=0;
    while (idx<n) {
        left+=2*tmp;
        left-=a[idx];
        right-=a[idx];
        idx++;
        tmp=0;
        while (idx<n&&op[idx]=='+') {
            tmp+=a[idx];
            left-=a[idx];
            right-=a[idx];
            idx++;
        }
        ans=max(ans,left+right);
    }
    ans=max(ans,left+right);
    printf("%lld\n",ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:5: error: reference to 'left' is ambiguous
   26 |     left=a[0];
      |     ^~~~
In file included from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:31:9: error: reference to 'right' is ambiguous
   31 |         right+=a[i];
      |         ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:21:11: note:                 'long long int right'
   21 | ll left=0,right=0,ans=-2e11;
      |           ^~~~~
a.cc:35:9: error: reference to 'left' is ambiguous
   35 |         left+=a[idx];
      |         ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:36:9: error: reference to 'right' is ambiguous
   36 |         right-=a[idx];
      |         ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:21:11: note:                 'long long int right'
   21 | ll left=0,right=0,ans=-2e11;
      |           ^~~~~
a.cc:41:9: error: reference to 'left' is ambiguous
   41 |         left+=2*tmp;
      |         ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:42:9: error: reference to 'left' is ambiguous
   42 |         left-=a[idx];
      |         ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:43:9: error: reference to 'right' is ambiguous
   43 |         right-=a[idx];
      |         ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:21:11: note:                 'long long int right'
   21 | ll left=0,right=0,ans=-2e11;
      |           ^~~~~
a.cc:48:13: error: reference to 'left' is ambiguous
   48 |             left-=a[idx];
      |             ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:49:13: error: reference to 'right' is ambiguous
   49 |             right-=a[idx];
      |             ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:21:11: note:                 'long long int right'
   21 | ll left=0,right=0,ans=-2e11;
      |           ^~~~~
a.cc:52:21: error: reference to 'left' is ambiguous
   52 |         ans=max(ans,left+right);
      |                     ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:52:26: error: reference to 'right' is ambiguous
   52 |         ans=max(ans,left+right);
      |                          ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:21:11: note:                 'long long int right'
   21 | ll left=0,right=0,ans=-2e11;
      |           ^~~~~
a.cc:54:17: error: reference to 'left' is ambiguous
   54 |     ans=max(ans,left+right);
      |                 ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:21:4: note:                 'long long int left'
   21 | ll left=0,right=0,ans=-2e11;
      |    ^~~~
a.cc:54:22: error: reference to 'right' is ambiguous
   54 |     ans=max(ans,left+right);
      |                      ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:21:11: note:                 'long long int right'
   21 | ll left=0,right=0,ans=-2e11;
      |           ^~~~~