Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long

struct data {
  int pos, num;
};

main()
{
  int n, k;
  int sum[200005] = {}
  bool flag[200005] = {};
  int ans = 0;
  queue < data > que;
  
  cin >> n >> k;

  for(int i = 1; i <= n; i++) {
    cin >> sum[i];
    sum[i] += sum[i - 1];
    if(sum[i] >= i * k) {
      que.push((data) { i, 1 });
      flag[i] = true; ans++;
    }
  }
  
  for(int i = 2; i <= n; i++) {
    while(true) {
      data d = que.front(); que.pop();
      if(d.pos == i) break;

      if(!flag[d.pos - 1] && d.pos - 1 > 0 && sum[d.pos - 1] - sum[i - 1] >= (d.pos - i) * k) {
	que.push((data) { d.pos - 1, i });
	flag[d.pos - 1] = true;
	ans++;
      }
      
      if(!flag[d.pos + 1] &&d.pos + 1 > 0 && sum[d.pos + 1] - sum[i - 1] >= (d.pos - i + 2) * k) {
	que.push((data) { d.pos + 1, i });
	flag[d.pos + 1] = true;
	ans++;
      }
    }
  }

  cout << ans << endl;

  return (0);
}


Compiler output:
a.cc:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:14:3: error: expected ',' or ';' before 'bool'
   14 |   bool flag[200005] = {};
      |   ^~~~
a.cc:16:16: error: template argument 1 is invalid
   16 |   queue < data > que;
      |                ^
a.cc:16:16: error: template argument 2 is invalid
a.cc:24:11: error: request for member 'push' in 'que', which is of non-class type 'int'
   24 |       que.push((data) { i, 1 });
      |           ^~~~
a.cc:24:17: error: reference to 'data' is ambiguous
   24 |       que.push((data) { i, 1 });
      |                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/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:6:8: note:                 'struct data'
    6 | struct data {
      |        ^~~~
a.cc:25:7: error: 'flag' was not declared in this scope
   25 |       flag[i] = true; ans++;
      |       ^~~~
a.cc:31:7: error: reference to 'data' is ambiguous
   31 |       data d = que.front(); que.pop();
      |       ^~~~
/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:6:8: note:                 'struct data'
    6 | struct data {
      |        ^~~~
a.cc:31:33: error: request for member 'pop' in 'que', which is of non-class type 'int'
   31 |       data d = que.front(); que.pop();
      |                                 ^~~
a.cc:32:10: error: 'd' was not declared in this scope
   32 |       if(d.pos == i) break;
      |          ^
a.cc:34:11: error: 'flag' was not declared in this scope
   34 |       if(!flag[d.pos - 1] && d.pos - 1 > 0 && sum[d.pos - 1] - sum[i - 1] >= (d.pos - i) * k) {
      |           ^~~~
a.cc:34:16: error: 'd' was not declared in this scope
   34 |       if(!flag[d.pos - 1] && d.pos - 1 > 0 && sum[d.pos - 1] - sum[i - 1] >= (d.pos - i) * k) {
      |                ^
a.cc:35:13: error: request for member 'push' in 'que', which is of non-class type 'int'
   35 |         que.push((data) { d.pos - 1, i });
      |             ^~~~
a.cc:35:19: error: reference to 'data' is ambiguous
   35 |         que.push((data) { d.pos - 1, 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:6:8: note:                 'struct data'
    6 | struct data {
      |        ^~~~
a.cc:40:11: error: 'flag' was not declared in this scope
   40 |       if(!flag[d.pos + 1] &&d.pos + 1 > 0 && sum[d.pos + 1] - sum[i - 1] >= (d.pos - i + 2) * k) {
      |           ^~~~
a.cc:40:16: error: 'd' was not declared in this scope
   40 |       if(!flag[d.pos + 1] &&d.pos + 1 > 0 && sum[d.pos + 1] - sum[i - 1] >= (d.pos - i + 2) * k) {
      |                ^
a.cc:41:13: error: request for member 'push' in 'que', which is of non-class type 'int'
   41 |         que.push((data) { d.pos + 1, i });
      |             ^~~~
a.cc:41:19: error: reference to 'data' is ambiguous
   41 |         que.push((data) { d.pos + 1, 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:6:8: note:                 'struct data'
    6 | struct data {
      |        ^~~~