Language: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;


long long dis[100050];
long long nutri[100050];
long long clock[100050];
long long clock_ret[100050];
long long cclock[100050];
long long cclock_ret[100050];
int main()
{
    long long sum=0;
    long long n,c;
    cin>>n>>c;
    long long ans=0;
    for(int i=1;i<=n;i++){

        scanf("%lld",&dis[i]);
        scanf("%lld",&nutri[i]);
        clock[i] = nutri[i-1]+nutri[i]-dis[i];
        sum+=nutri[i];
        nutri[i] += nutri[i-1];
        clock_ret[i] = max(clock_ret[i-1],clock[i]-dis[i]);
    }
    for(int i=n;i>0;i--){
        cclock[i] = sum - nutri[i-1]-(c-dis[i]);
        cclock_ret[i] = max(cclock_ret[i+1],cclock[i]-(c-dis[i]));
    }
    for(int i=1;i<=n;i++){
        ans = max(ans,clock[i]);
        ans = max(ans,cclock[i]);
        ans = max(ans,clock_ret[i-1]+cclock[i]);
        ans = max(ans,cclock_ret[i+1]+clock[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc:9:23: error: 'long long int clock [100050]' redeclared as different kind of entity
    9 | long long clock[100050];
      |                       ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/time.h:72:16: note: previous declaration 'clock_t clock()'
   72 | extern clock_t clock (void) __THROW;
      |                ^~~~~
a.cc: In function 'int main()':
a.cc:23:16: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |         clock[i] = nutri[i-1]+nutri[i]-dis[i];
      |                ^
a.cc:23:18: error: assignment of read-only location '*(clock + ((sizetype)i))'
   23 |         clock[i] = nutri[i-1]+nutri[i]-dis[i];
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:26:50: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   26 |         clock_ret[i] = max(clock_ret[i-1],clock[i]-dis[i]);
      |                                                  ^
a.cc:26:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   26 |         clock_ret[i] = max(clock_ret[i-1],clock[i]-dis[i]);
      |                                           ~~~~~~~~^~~~~~~
a.cc:26:27: error: no matching function for call to 'max(long long int&, clock_t (*)() noexcept)'
   26 |         clock_ret[i] = max(clock_ret[i-1],clock[i]-dis[i]);
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41:
/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:26:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'clock_t (*)() noexcept' {aka 'long int (*)() noexcept'})
   26 |         clock_ret[i] = max(clock_ret[i-1],clock[i]-dis[i]);
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:2:
/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:26:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   26 |         clock_ret[i] = max(clock_ret[i-1],clock[i]-dis[i]);
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:33:30: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |         ans = max(ans,clock[i]);
      |                              ^
a.cc:33:18: error: no matching function for call to 'max(long long int&, clock_t (&)() noexcept)'
   33 |         ans = max(ans,clock[i]);
      |               ~~~^~~~~~~~~~~~~~
/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:33:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'clock_t() noexcept' {aka 'long int() noexcept'})
   33 |         ans = max(ans,clock[i]);
      |               ~~~^~~~~~~~~~~~~~
/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:33:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |         ans = max(ans,clock[i]);
      |               ~~~^~~~~~~~~~~~~~
a.cc:36:46: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   36 |         ans = max(ans,cclock_ret[i+1]+clock[i]);
      |                                              ^
a.cc:36:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   36 |         ans = max(ans,cclock_ret[i+1]+clock[i]);
      |                       ~~~~~~~~~~~~~~~^~~~~~~~~
a.cc:36:18: error: no matching function for call to 'max(long long int&, clock_t (*)() noexcept)'
   36 |         ans = max(ans,cclock_ret[i+1]+clock[i]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:36:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'clock_t (*)() noexcept' {aka 'long int (*)() noexcept'})
   36 |         ans = max(ans,cclock_ret[i+1]+clock[i]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:36:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |         ans = max(ans,cclock_ret[i+1]+clock[i]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~