Language: C++

#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;
#define INF (1<<29)

int time[100002];
int data[100002];

int main(){
	
	for(int i = 0 ; i < 100002 ; i++)
		time[i] = -1;
	int n,L;
	cin >> n >> L;
	
	time[0] = time[n+1] = data[n+1] = data[0] = 0 ;
	
	priority_queue< pair<int,int> > Q;
	for(int i = 1 ; i <= n ; i++){
		cin >> data[i];
		Q.push(make_pair(data[i],i));
	}
	int s = 0;
	while(Q.size()){

		int len = Q.top().first , index = Q.top().second ; Q.pop();
		if( data[index-1] < data[index] && data[index+1] < data[index]){
			len = min(L , len+s);
		}else if(~time[index-1] && ~time[index+1]){
			len = min(L , (s-max(time[index+1],time[index-1]) + len) );
		}else if(~time[index-1]){
			len = min(L , (s-time[index-1]) + len);
		}else if(~time[index+1]){
			len = min(L , (s-time[index+1]) + len);
		}else{
			assert(0);
		}
		int usetime = L - len;
		s += usetime;
		time[index] = s;
	}
	cout << s << endl;
}

Compiler output:
a.cc:8:16: error: 'int time [100002]' redeclared as different kind of entity
    8 | int time[100002];
      |                ^
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:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'int main()':
a.cc:14:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   14 |                 time[i] = -1;
      |                       ^
a.cc:14:25: error: assignment of read-only location '*(time + ((sizetype)i))'
   14 |                 time[i] = -1;
      |                 ~~~~~~~~^~~~
a.cc:18:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   18 |         time[0] = time[n+1] = data[n+1] = data[0] = 0 ;
      |               ^
a.cc:18:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   18 |         time[0] = time[n+1] = data[n+1] = data[0] = 0 ;
      |                           ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:18:31: error: reference to 'data' is ambiguous
   18 |         time[0] = time[n+1] = data[n+1] = data[0] = 0 ;
      |                               ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:18:43: error: reference to 'data' is ambiguous
   18 |         time[0] = time[n+1] = data[n+1] = data[0] = 0 ;
      |                                           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:22:24: error: reference to 'data' is ambiguous
   22 |                 cin >> data[i];
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:23:34: error: reference to 'data' is ambiguous
   23 |                 Q.push(make_pair(data[i],i));
      |                                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:29:21: error: reference to 'data' is ambiguous
   29 |                 if( data[index-1] < data[index] && data[index+1] < data[index]){
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:29:37: error: reference to 'data' is ambiguous
   29 |                 if( data[index-1] < data[index] && data[index+1] < data[index]){
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:29:52: error: reference to 'data' is ambiguous
   29 |                 if( data[index-1] < data[index] && data[index+1] < data[index]){
      |                                                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:5: note:                 'int data [100002]'
    9 | int data[100002];
      |     ^~~~
a.cc:29:68: error: reference to 'data' is ambiguous
   29 |                 if( data[index-1] < data[index] && data[