Language: C++

#include <iostream>
#include <vector>

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P;
  for (int i = 0; i < N; i++) {
    int Pi;
    cin >> Pi;
    P.push_back(Pi);
  }
  int res = 0;
  for (int i = 0; i <= N - K; i++) {
    res = max(res, kitaiti(i, A, K));
  }
  cout << res << endl;
}

float kitaiti (int index, vector<int> a, int k) {
  float res = 0;
  for (int i = index; i < index + k; i++) {
    int all = 0;
    for (int j = 1; j <= a[i]; j++) {
      all += j;
    }
    res += (1 / a[i]) * all;
  }
  return res;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    6 |   cin >> N >> K;
      |   ^~~
      |   std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:7:3: error: 'vector' was not declared in this scope
    7 |   vector<int> P;
      |   ^~~~~~
a.cc:7:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:7:10: error: expected primary-expression before 'int'
    7 |   vector<int> P;
      |          ^~~
a.cc:11:5: error: 'P' was not declared in this scope; did you mean 'Pi'?
   11 |     P.push_back(Pi);
      |     ^
      |     Pi
a.cc:15:31: error: 'A' was not declared in this scope
   15 |     res = max(res, kitaiti(i, A, K));
      |                               ^
a.cc:15:20: error: 'kitaiti' was not declared in this scope
   15 |     res = max(res, kitaiti(i, A, K));
      |                    ^~~~~~~
a.cc:15:11: error: 'max' was not declared in this scope; did you mean 'std::max'?
   15 |     res = max(res, kitaiti(i, A, K));
      |           ^~~
      |           std::max
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,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:17:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   17 |   cout << res << endl;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:17:18: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   17 |   cout << res << endl;
      |                  ^~~~
      |                  std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: At global scope:
a.cc:20:27: error: 'vector' has not been declared
   20 | float kitaiti (int index, vector<int> a, int k) {
      |                           ^~~~~~
a.cc:20:33: error: expected ',' or '...' before '<' token
   20 | float kitaiti (int index, vector<int> a, int k) {
      |                                 ^
a.cc: In function 'float kitaiti(int, int)':
a.cc:22:35: error: 'k' was not declared in this scope
   22 |   for (int i = index; i < index + k; i++) {
      |                                   ^
a.cc:24:26: error: 'a' was not declared in this scope
   24 |     for (int j = 1; j <= a[i]; j++) {
      |                          ^
a.cc:27:17: error: 'a' was not declared in this scope
   27 |     res += (1 / a[i]) * all;
      |                 ^