Language: C++

#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int W, A[100002];
int close[100002];

int main()
{
  cin >> W;
  for(int i = 1; i <= W; i++) {
    cin >> A[i];
    if(A[i] == 0) close[i] = INF;
  }
  for(int i = 1; i <= W; i++) {
    close[i] = max(close[i], close[i - 1] - 1);
    if(A[i] < 0) close[i] = min(close[i], -A[i]);
  }
  for(int i = W; i >= 1; i--) {
    close[i] = max(close[i], close[i + 1] - 1);
    if(A[i] < 0) close[i] = min(close[i], -A[i]);
  }
  int ret = 0;
  for(int i = 1; i <= W; i++) {
    ret += max(0, min(close[i], A[i]));
  }
  cout << ret << endl;
}

Compiler output:
a.cc:6:17: error: 'int close [100002]' redeclared as different kind of entity
    6 | int close[100002];
      |                 ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:358:12: note: previous declaration 'int close(int)'
  358 | extern int close (int __fd);
      |            ^~~~~
a.cc: In function 'int main()':
a.cc:13:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   13 |     if(A[i] == 0) close[i] = INF;
      |                          ^
a.cc:13:28: error: assignment of read-only location '*(close + ((sizetype)i))'
   13 |     if(A[i] == 0) close[i] = INF;
      |                   ~~~~~~~~~^~~~~
a.cc:16:12: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |            ^
a.cc:16:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |                           ^
a.cc:16:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |                                         ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:16:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |                              ~~~~~~~~~~~~~^~~
a.cc:16:19: error: no matching function for call to 'max(int (&)(int), int (*)(int))'
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:16:19: note:   deduced conflicting types for parameter 'const _Tp' ('int(int)' and 'int (*)(int)')
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:16:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int (*)(int)'
   16 |     close[i] = max(close[i], close[i - 1] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:17:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   17 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                         ^
a.cc:17:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   17 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                                        ^
a.cc:17:32: error: no matching function for call to 'min(int (&)(int), int)'
   17 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                             ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:17:32: note:   deduced conflicting types for parameter 'const _Tp' ('int(int)' and 'int')
   17 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                             ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:17:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int (*)(int)'
   17 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                             ~~~^~~~~~~~~~~~~~~~~
a.cc:20:12: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |            ^
a.cc:20:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |                           ^
a.cc:20:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |                                         ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:20:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |                              ~~~~~~~~~~~~~^~~
a.cc:20:19: error: no matching function for call to 'max(int (&)(int), int (*)(int))'
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:20:19: note:   deduced conflicting types for parameter 'const _Tp' ('int(int)' and 'int (*)(int)')
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:20:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int (*)(int)'
   20 |     close[i] = max(close[i], close[i + 1] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:21:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                         ^
a.cc:21:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                                        ^
a.cc:21:32: error: no matching function for call to 'min(int (&)(int), int)'
   21 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                             ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:21:32: note:   deduced conflicting types for parameter 'const _Tp' ('int(int)' and 'int')
   21 |     if(A[i] < 0) close[i] = min(close[i], -A[i]);
      |                             ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c