prithivMLmods/Coder-Stat huggingface dataset:
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

double func(int x) {
  double ret = 0;
  for (int i = 1; i <= x; i++) {
    ret += i;
  }
  return ret / x;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<double> s(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i <= n; i++) {
    s[i + 1] = s[i] + func(p[i]);
  }
  double ans = 0;
  int right = 0;
  for (int left = 0; left < n; left++) {
    while (right < n && (right + 1 - left <= k)) {
      ++right;
    }
    ans = max(ans, s[right] - s[left]);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

double func(int x) {
  double ret = 0;
  for (int i = 1; i <= x; i++) {
    ret += i;
  }
  return ret / x;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<double> s(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    s[i + 1] = s[i] + func(p[i]);
  }
  double ans = 0;
  int right = 0;
  for (int left = 0; left < n; left++) {
    while (right < n && (right + 1 - left <= k)) {
      ++right;
    }
    ans = max(ans, s[right] - s[left]);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> P(N);
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    P[i + 1] = v * (v + 1) / 2.0 / v;
    P[i + 1] += P[i];
  }

  double ans = 0;
  for (int i = 0; i + K <= N; i++) {
    double S = P[i + K] - P[i];
    chmax(ans, S);
  }
  printf("%.12f\n", ans);
  return 0;
}


Fixed submission:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> P(N + 1);
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    P[i + 1] = v * (v + 1) / 2.0 / v;
    P[i + 1] += P[i];
  }

  double ans = 0;
  for (int i = 0; i + K <= N; i++) {
    double S = P[i + K] - P[i];
    chmax(ans, S);
  }
  printf("%.12f\n", ans);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();

  ll N, K;
  cin >> N >> K;

  vector<ll> p(N);
  vector<double> d(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (i != 0)
      d[i] = d[i - 1] + (1.0 + p[i]) / 2;
    else
      d[i] = (1.0 + p[i]) / 2;
  }

  double maxv = 0;
  for (int i = 0; i < N; i++) {
    if (i != 0)
      maxv = max(maxv, d[i + K - 1] - d[i - 1]);
    else
      maxv = max(maxv, d[i + K - 1]);
  }

  cout << fixed << setprecision(10) << maxv << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();

  ll N, K;
  cin >> N >> K;

  vector<ll> p(N);
  vector<double> d(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (i != 0)
      d[i] = d[i - 1] + (1.0 + p[i]) / 2;
    else
      d[i] = (1.0 + p[i]) / 2;
  }

  double maxv = 0;
  for (int i = 0; i + K - 1 < N; i++) {
    if (i != 0)
      maxv = max(maxv, d[i + K - 1] - d[i - 1]);
    else
      maxv = max(maxv, d[i + K - 1]);
  }

  cout << fixed << setprecision(10) << maxv << endl;

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
typedef long long ll;
int main() {
  ll N, K;
  cin >> N >> K;
  vector<double> P(N);
  vector<double> PD(N);
  rep(i, 0, N) {
    cin >> P[i];
    PD[i] = (((1 + P[i]) * P[i]) / 2) / P[i];
  }
  double ans = 0;
  rep(i, 0, N - K + 1) {
    double tmp = 0;
    ll n = i + K;
    rep(j, i, n) { tmp += PD[j]; }
    if (tmp > ans) {
      ans = tmp;
    }
  }
  printf("%.12f", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
typedef long long ll;
int main() {
  ll N, K;
  cin >> N >> K;
  vector<double> P(N);
  vector<double> PD(N);
  rep(i, 0, N) {
    cin >> P[i];
    PD[i] = (((1 + P[i]) * P[i]) / 2) / P[i];
  }
  double ans = 0;
  ll index = 0;
  double tmp = 0;
  rep(i, 0, N) {
    if (i >= K) {
      tmp -= PD[index];
      index++;
    }
    tmp += PD[i];
    if (tmp > ans) {
      ans = tmp;
    }
  }
  printf("%.12f", ans);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 200000;
int n, k;
double p[MAX_N];
double e[MAX_N];

void solve() {
  for (int i = 0; i < n; i++) {
    e[i] = (p[i] + 1) / 2;
  }

  double s[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      s[i] += e[j];
    }
  }

  double ans[n - k + 1];
  double max = ans[0] = s[k - 1];
  for (int i = 1; i < n - k + 1; i++) {
    ans[i] = s[i + k - 1] - s[i - 1];
    if (ans[i] > max) {
      max = ans[i];
    }
  }

  printf("%.10f\n", max);
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  solve();
}

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

const int MAX_N = 200000;
int n, k;
double p[MAX_N];
double e[MAX_N];

void solve() {
  for (int i = 0; i < n; i++) {
    e[i] = (p[i] + 1) / 2;
  }

  double s[n];
  s[0] = e[0];
  for (int i = 1; i < n; i++) {
    s[i] = s[i - 1] + e[i];
  }

  double ans[n - k + 1];
  double max = ans[0] = s[k - 1];
  for (int i = 1; i < n - k + 1; i++) {
    ans[i] = s[i + k - 1] - s[i - 1];
    if (ans[i] > max) {
      max = ans[i];
    }
  }

  printf("%.10f\n", max);
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  solve();
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll << 60)
#else
#define inf (1 << 30)
#endif
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a, b) for (int i = (a); i <= (b); i++)
#define rev(i, n) for (int i = (n)-1; i >= 0; i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a, 0, sizeof(a))
#define Yes(f) cout << (f ? "Yes" : "No") << endl
#define yes(f) cout << (f ? "yes" : "no") << endl
#define YES(f) cout << (f ? "YES" : "NO") << endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod = 1e9 + 7;
const string sp = " ";

void run();

void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
}

signed main() {
  init();
  run();
  return 0;
}

double f(double n) { return n * (n + 1) / 2 / n; }

void run() {
  int n, k;
  cin >> n >> k;
  vector<double> p(n + 1);
  REP(i, 1, n) {
    cin >> p[i];
    p[i] = f(p[i]);
  }
  rep(i, n) p[i + 1] += p[i];
  double ans = 0;
  rep(i, n) { ans = max(ans, p[i + k] - p[i]); }
  cout << ans << endl;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll << 60)
#else
#define inf (1 << 30)
#endif
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a, b) for (int i = (a); i <= (b); i++)
#define rev(i, n) for (int i = (n)-1; i >= 0; i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a, 0, sizeof(a))
#define Yes(f) cout << (f ? "Yes" : "No") << endl
#define yes(f) cout << (f ? "yes" : "no") << endl
#define YES(f) cout << (f ? "YES" : "NO") << endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod = 1e9 + 7;
const string sp = " ";

void run();

void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
}

signed main() {
  init();
  run();
  return 0;
}

double f(double n) { return n * (n + 1) / 2 / n; }

void run() {
  int n, k;
  cin >> n >> k;
  vector<double> p(n + 1);
  REP(i, 1, n) {
    cin >> p[i];
    p[i] = f(p[i]);
  }
  rep(i, n) p[i + 1] += p[i];
  double ans = 0;
  rep(i, n - k + 1) { ans = max(ans, p[i + k] - p[i]); }
  cout << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, 0, n) cin >> p[i];
  vector<double> cusum(n + 1, 0);
  rep(i, 0, n + 1) cusum[i + 1] = cusum[i] + (p[i] + 1) / (double)2;
  double ans = 0;
  rep(i, 0, n - k + 1) ans = max(ans, cusum[i + k] - cusum[i]);
  cout << fixed << setprecision(15);
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, 0, n) cin >> p[i];
  vector<double> cusum(n + 1, 0);
  rep(i, 0, n) cusum[i + 1] = cusum[i] + (p[i] + 1) / (double)2;
  double ans = 0;
  rep(i, 0, n - k + 1) ans = max(ans, cusum[i + k] - cusum[i]);
  cout << fixed << setprecision(15);
  cout << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int p[200010];
double P[200010];
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    for (int j = 1; j <= p[i]; j++) {
      P[i] += (double)j / p[i];
    }
  }
  double ans = 0;
  for (int i = 0; i <= N - K; i++) {
    double sum = 0;
    for (int j = i; j < i + K; j++) {
      sum += P[j];
    }
    // cout << sum << endl;
    ans = max(ans, sum);
  }
  printf("%.6f", ans);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int p[200010];
double P[200010];
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    for (int j = 1; j <= p[i]; j++) {
      P[i] += (double)j / p[i];
    }
  }
  double ans = 0.0, sum = 0;
  for (int i = 0; i < K; i++) {
    sum += P[i];
  }
  ans = sum;
  for (int i = K; i < N; i++) {
    sum -= P[i - K];
    sum += P[i];
    ans = max(sum, ans);
  }
  printf("%.6f", ans);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> p(n);
  for (ll i = 0; i < n; i++)
    cin >> p[i];
  vector<double> exp(n);
  for (ll i = 0; i < n; i++) {
    exp[i] = (p[i] + 1) / 2.0;
  }
  double ans = 0;
  for (ll i = 0; i + k - 1 < n; i++) {
    double temp = 0;
    for (ll j = 0; j < k; j++) {
      temp += exp[i + j];
    }
    ans = max(ans, temp);
  }

  printf("%.10f\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> p(n);
  for (ll i = 0; i < n; i++)
    cin >> p[i];
  vector<double> exp(n);
  for (ll i = 0; i < n; i++) {
    exp[i] = (p[i] + 1) / 2.0;
  }
  double ans = 0;
  for (ll i = 0; i < k; i++)
    ans += exp[i];
  double temp = ans;
  for (ll i = 1; i + k - 1 < n; i++) {
    temp -= exp[i - 1];
    temp += exp[i + k - 1];
    ans = max(ans, temp);
  }

  printf("%.10f\n", ans);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int N = 200005;
int n, k;
double p[N], sum = 0, res = 0;
double dp[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
  }
  for (int i = 1; i <= n - k + 1; i++) {
    res = 0;
    for (int j = i; j < i + k; j++) {
      res += p[j];
    }
    sum = max(sum, res);
  }
  printf("%.12lf", (sum + k) / 2.0);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int N = 200005;
int n, k;
double p[N], sum = 0, res = 0;
double dp[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
  }
  for (int i = 1; i <= n - k + 1; i++) {
    if (i == 1) {
      for (int j = i; j < i + k; j++) {
        res += p[j];
      }
    } else {
      res -= p[i - 1];
      res += p[i + k - 1];
    }
    sum = max(sum, res);
  }
  printf("%.12lf", (sum + k) / 2.0);
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long double ll;

int Array(int x[], int n) {
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  return *x;
}

int main() {
  int n, k;
  cin >> n >> k;
  int p[n];
  vector<ll> ktit(n);
  vector<ll> riskw(n + 1);
  Array(p, n);
  ll sum = 0;
  ll ans = 0;

  for (int i = 0; i < n; i++) {
    ll s = (p[i] + 1);
    s /= 2;
    ktit.push_back(s);
    riskw[i + 1] = s;
  }

  for (int i = 1; i <= n; i++) {
    riskw[i] += riskw[i - 1];
  }

  for (int i = 0; i <= n; i++) {
    ll x = riskw[i + k] - riskw[i];
    if (x > ans) {
      ans = x;
    }
  }
  cout << setprecision(8) << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long double ll;

int Array(int x[], int n) {
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  return *x;
}

int main() {
  int n, k;
  cin >> n >> k;
  int p[n];
  vector<ll> ktit(n);
  vector<ll> riskw(n + 1);
  Array(p, n);
  ll sum = 0;
  ll ans = 0;

  for (int i = 0; i < n; i++) {
    ll s = (p[i] + 1);
    s /= 2;
    ktit.push_back(s);
    riskw[i + 1] = s;
  }

  for (int i = 1; i <= n; i++) {
    riskw[i] += riskw[i - 1];
  }

  for (int i = k; i <= n; i++) {
    ll x = riskw[i] - riskw[i - k];
    if (x > ans) {
      ans = x;
    }
  }
  cout << setprecision(8) << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  freopen("10.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  int ans = sum;
  for (int i = k; i < n; ++i) {
    sum += p[i];
    sum -= p[i - k];
    ans = max(ans, sum);
  }
  cout << setprecision(30) << (double)(ans + k) / 2.0 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  int ans = sum;
  for (int i = k; i < n; ++i) {
    sum += p[i];
    sum -= p[i - k];
    ans = max(ans, sum);
  }
  cout << setprecision(30) << (double)(ans + k) / 2.0 << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
// ABC_154_D

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

#define forn(i, n) for (int i = 0; i < (int)n; ++i)

int sum(int n) {
  int sum = n * (n + 1) / 2;

  return sum;
}

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  forn(i, n) cin >> v[i];

  vector<double> expv(n, 0);
  forn(i, n) {
    double tmp = 0;
    tmp = (double)sum(v[i]) / (double)v[i];
    expv[i] = tmp;
  }

  // sum
  vector<double> sum(n + 1, 0);
  forn(i, n + 1) sum[i + 1] = sum[i] + expv[i];

  double max = 0;
  for (int j = 0; j <= n - k; ++j) {
    double tmp = sum[j + k] - sum[j];

    // cout << tmp << "\n";

    if (max < tmp)
      max = tmp;
  }

  cout << fixed << setprecision(15);
  cout << max << "\n";
}

Fixed submission:
// ABC_154_D

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

#define forn(i, n) for (int i = 0; i < (int)n; ++i)

int sum(int n) {
  int sum = n * (n + 1) / 2;

  return sum;
}

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  forn(i, n) cin >> v[i];

  vector<double> expv(n, 0);
  forn(i, n) {
    double tmp = 0;
    tmp = (double)sum(v[i]) / (double)v[i];
    expv[i] = tmp;
  }

  // sum
  vector<double> sum(n + 1, 0);
  forn(i, n) sum[i + 1] = sum[i] + expv[i];

  double max = 0;
  for (int j = 0; j <= n - k; ++j) {
    double tmp = sum[j + k] - sum[j];

    // cout << tmp << "\n";

    if (max < tmp)
      max = tmp;
  }

  cout << fixed << setprecision(15);
  cout << max << "\n";
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int K, N;
  cin >> N >> K;
  double p[N];
  rep(i, N) cin >> p[i];

  rep(i, N) p[i] = (p[i] + 1) / 2.0;
  double ans = 0.0;
  double sum = 0.0;
  rep(i, N - K + 1) {
    sum = 0.0;
    rep(j, K) { sum += p[i + j]; }
    ans = max(ans, sum);
  }
  cout << fixed << setprecision(14);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int K, N;
  cin >> N >> K;
  double p[N];
  rep(i, N) cin >> p[i];

  rep(i, N) p[i] = (p[i] + 1) / 2.0;
  double ans = 0.0;
  double sum = 0;
  rep(i, K) ans += p[i];
  sum = ans;
  for (int i = K; i < N; i++) {
    sum += p[i];
    sum -= p[i - K];
    ans = max(ans, sum);
  }
  cout << fixed << setprecision(14);
  cout << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long int I;

int keta(int a) {
  int count = 0;
  while (a != 0) {
    a /= 10;
    count++;
  }
  return count;
}

int main() {
  int n, k;
  double ans = 0, m = 0;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - k + 1; i++) {
    m = k;
    for (int j = i; j < i + k; j++) {
      m += a[j];
    }
    ans = max(m, ans);
  }
  ans = double(ans);
  cout << fixed;
  cout << setprecision(8) << ans / 2.0 << endl;

  return 0;
} // カモンAC

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long int I;

int keta(int a) {
  int count = 0;
  while (a != 0) {
    a /= 10;
    count++;
  }
  return count;
}

int main() {
  int n, k;
  double ans = 0, m = 0;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  m = k;
  for (int i = 0; i < k; i++) {
    m += a[i];
  }
  ans = m;
  for (int i = k; i < n; i++) {
    m += a[i] - a[i - k];
    ans = max(ans, m);
  }
  ans = double(ans);
  cout << fixed;
  cout << setprecision(8) << ans / 2.0 << endl;

  return 0;
} // カモンAC
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;

using namespace std;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

template <typename T> T finder(vector<T> vec, T number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}
ll frac(ll n) {
  if (n == 0) {
    return 1;
  }
  return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
        yaju[i] = r[i] - '0';
}
*/
int main() {
  ll N, K;
  cin >> N >> K;
  vector<double> B(N);
  double ans = 0;
  double max = 0;
  double x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    for (int j = 1; j <= x; j++) {
      B[i] += j * (1 / x);
    }
  }
  for (int i = 0; i < N - K + 1; i++) {
    max = 0;
    for (int k = i; k < i + K; k++) {
      max += B[k];
    }
    if (max > ans)
      ans = max;
  }
  cout << fixed << setprecision(13) << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;

using namespace std;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

template <typename T> T finder(vector<T> vec, T number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}
ll frac(ll n) {
  if (n == 0) {
    return 1;
  }
  return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
        yaju[i] = r[i] - '0';
}
*/
int main() {
  ll N, K;
  cin >> N >> K;
  vector<double> B(N);
  double ans = 0;
  double max = 0;
  double x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    for (int j = 1; j <= x; j++) {
      B[i] += j * (1 / x);
    }
  }
  double l = 0;
  for (int i = 0; i < K; i++)
    l += B[i];
  ans = l;
  for (int i = 0; i < N - K; i++) {
    l -= B[i];
    l += B[i + K];
    if (l > ans)
      ans = l;
  }
  cout << fixed << setprecision(13) << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> v(n);
  cout << fixed << setprecision(6);
  rep(i, n) {
    cin >> v.at(i);
    v.at(i) = (v.at(i) + 1) / 2;
    // cout<<v.at(i)<<" ";
  }
  double ans, ansm = 0;
  rep(i, n - k + 1) {
    ans = 0;
    for (int j = i; j < i + k; j++) {
      ans += v.at(j);
    }
    ansm = max(ans, ansm);
  }

  cout << ansm;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> v(n);
  cout << fixed << setprecision(6);
  rep(i, n) {
    cin >> v.at(i);
    v.at(i) = (v.at(i) + 1) / 2;
    // cout<<v.at(i)<<" ";
  }
  double ans = 0;
  rep(i, k) { ans += v.at(i); }
  double ansm = ans;
  rep(i, n - k) {
    ans = ans - v.at(i) + v.at(i + k);
    ansm = max(ans, ansm);
  }

  cout << ansm;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>

double avg(int n) { return (n + 1) / 2.0; }

int main() {
  int n, k, p[200];
  std::cin >> n >> k;

  for (int i = 0; i < n; ++i)
    std::cin >> p[i];

  double sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += avg(p[i]);
  }

  double ans = sum;
  for (int i = k; i < n; ++i) {
    sum -= avg(p[i - k]);
    sum += avg(p[i]);

    ans = std::max(ans, sum);
  }

  std::cout << std::setprecision(10) << std::fixed << ans;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>

double avg(int n) { return (n + 1) / 2.0; }

int main() {
  int n, k, p[2000010];
  std::cin >> n >> k;

  for (int i = 0; i < n; ++i)
    std::cin >> p[i];

  double sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += avg(p[i]);
  }

  double ans = sum;
  for (int i = k; i < n; ++i) {
    sum -= avg(p[i - k]);
    sum += avg(p[i]);

    ans = std::max(ans, sum);
  }

  std::cout << std::setprecision(10) << std::fixed << ans;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int n, k;
double ex[200000], pre[200001];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double val;
    cin >> val;
    ex[i] = (val * (val + 1)) / (2 * val);
  }
  double mx = 0;
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + ex[i - 1];
    mx = max(mx, pre[i] - pre[i - k]);
  }
  cout << fixed << setprecision(6) << mx << "\n";
  return 0;
}

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

int n, k;
double ex[200000], pre[200001];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double val;
    cin >> val;
    ex[i] = (val * (val + 1)) / (2 * val);
  }
  double mx = 0;
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + ex[i - 1];
    mx = max(mx, pre[i] - pre[max(0, i - k)]);
  }
  cout << fixed << setprecision(6) << mx << "\n";
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

// 154-c
int main() {
  int n, k;
  cin >> n >> k;

  int p;
  vector<double> v;
  rep(i, 0, n) {
    cin >> p;
    double sum = p * (p + 1);
    double div = 2 * p;
    v.push_back(sum / div);
  }

  double mx = 0, sum = 0;
  for (int i = 0; i + k - 1 < n; i++) {
    sum = 0;
    rep(_k, 0, k) { sum += v[i + _k]; }
    mx = max(mx, sum);
  }

  printf("%lf\n", mx);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

// 154-c
int main() {
  int n, k;
  cin >> n >> k;

  int p;
  vector<double> v;
  rep(i, 0, n) {
    cin >> p;
    double sum = p * (p + 1);
    double div = 2 * p;
    v.push_back(sum / div);
  }

  double sum = 0;
  rep(i, 0, k) { sum += v[i]; }

  double mx = sum;
  for (int i = 1; i + k - 1 < n; i++) {
    sum += v[i + k - 1];
    sum -= v[i - 1];
    mx = max(mx, sum);
  }

  printf("%lf\n", mx);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {

  ll n, k;
  cin >> n >> k;

  vector<long double> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i];

  long double maxans = 0;
  for (int j = 0; j < n - k + 1; j++) {
    long double ans = 0;
    for (int i = j; i < k + j; i++) {
      ans += (p[i] + 1) / 2;
    }
    maxans = max(maxans, ans);
  }

  cout << fixed << setprecision(10) << maxans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {

  ll n, k;
  cin >> n >> k;

  vector<long double> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i];

  long double maxans = 0;
  for (int i = 0; i < k; i++) {
    maxans += (p[i] + 1) / 2;
  }

  long double ans = maxans;
  for (int i = 0; i < n - k + 1; i++) {
    ans += (p[i + k] - p[i]) / 2;
    maxans = max(maxans, ans);
  }

  cout << fixed << setprecision(10) << maxans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  rep(i, n - k + 1) {
    int now = 0;
    rep(j, k) { now += p[i + j]; }
    ans = max(now, ans);
  }
  double output = ans;
  output = output / 2.0 + 1.0 / 2.0 * k;
  printf("%.12lf\n", output);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int now = 0;
  for (int i = 0; i < k; i++)
    now += p[i];
  int ans = now;
  for (int i = k; i < n; i++) {
    now = now - p[i - k] + p[i];
    ans = max(ans, now);
  }
  double output = ans;
  output = output / 2.0 + 1.0 / 2.0 * k;
  printf("%.12lf\n", output);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> pref(n + 1), E(n);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    E[i] = (1.0 + x) / 2.0;
  }
  for (int i = 1; i <= n; ++i) {
    pref[i] = pref[i - 1] + E[i];
  }
  double ans = 0.0;
  for (int i = 0; i <= n - k; ++i) {
    ans = max(ans, pref[i + k] - pref[i]);
  }
  printf("%.10f\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> pref(n + 1), E(n + 1);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    E[i] = (1.0 + x) / 2.0;
  }
  for (int i = 1; i <= n; ++i) {
    pref[i] = pref[i - 1] + E[i];
  }
  double ans = 0.0;
  for (int i = 0; i <= n - k; ++i) {
    ans = max(ans, pref[i + k] - pref[i]);
  }
  printf("%.10f\n", ans);
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr << x << END;
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int inf = 1e18;
const int nax = 100005;
int a[nax], n, k;
void solve() {
  cin >> n >> k;
  loop(i, 0, n) cin >> a[i];
  int lo = 0, hi = 0;
  double sum = 0, ans = 0;
  loop(i, 0, k) sum += 1.0 * (a[i] + 1) / 2;
  ans = sum;
  hi = k - 1;
  loop(i, k, n) {
    sum -= 1.0 * (a[lo] + 1) / 2;
    lo++;
    sum += 1.0 * (a[i] + 1) / 2;
    hi++;
    if (hi - lo + 1 == k)
      ans = max(ans, sum);
  }
  cout << fixed << setprecision(10);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  /*int t;
  cin>>t;
  loop(i,1,t+1)*/
  solve();

  // cerr<<END<<1.0*clock();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr << x << END;
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int inf = 1e18;
const int nax = 200005;
int a[nax], n, k;
void solve() {
  cin >> n >> k;
  loop(i, 0, n) cin >> a[i];
  int lo = 0, hi = 0;
  double sum = 0, ans = 0;
  loop(i, 0, k) sum += 1.0 * (a[i] + 1) / 2;
  ans = sum;
  hi = k - 1;
  loop(i, k, n) {
    sum -= 1.0 * (a[lo] + 1) / 2;
    lo++;
    sum += 1.0 * (a[i] + 1) / 2;
    hi++;
    if (hi - lo + 1 == k)
      ans = max(ans, sum);
  }
  cout << fixed << setprecision(10);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  /*int t;
  cin>>t;
  loop(i,1,t+1)*/
  solve();

  // cerr<<END<<1.0*clock();
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <vector>

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  std::vector<double> sum = {0};
  double ret = 0;
  for (int i = 1; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    sum[i] = (p + 1) * 0.5 + sum[i - 1];
    if (i >= k && sum[i] - sum[i - k] >= ret)
      ret = sum[i] - sum[i - k];
  }
  printf("%.10f\n", ret);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <vector>

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  std::vector<double> sum(n + 1);
  double ret = 0;
  for (int i = 1; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    sum[i] = (p + 1) * 0.5 + sum[i - 1];
    if (i >= k && sum[i] - sum[i - k] >= ret)
      ret = sum[i] - sum[i - k];
  }
  printf("%.10f\n", ret);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  double ans = -1.0;
  int p[200000];
  double z[200000];
  cin >> n >> k;
  rep(i, n) {
    int q;
    double r;
    cin >> q;
    p[i] = q;

    ll t = ((1 + p[i]) * p[i]) / 2;
    z[i] = (double)t / p[i];

    if (i < k - 1)
      continue;
    double h = 0;
    rep(j, k) { h += z[i - j]; }
    ans = max(ans, h);
  }
  cout << fixed;
  cout << setprecision(12) << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  double ans = -1.0;
  int p[200000];
  double z[200000];
  cin >> n >> k;
  rep(i, n) {
    int q;
    double r;
    cin >> q;
    p[i] = q;

    ll t = ((1 + p[i]) * p[i]) / 2;
    z[i] = (double)t / p[i];

    if (i < k - 1)
      continue;

    double h;
    if (i == k - 1) {
      h = 0;
      rep(j, k) { h += z[i - j]; }
    } else if (i > k - 1) {
      h -= z[i - k];
      h += z[i];
    }
    ans = max(ans, h);
  }
  cout << fixed;
  cout << setprecision(12) << ans;

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  int n, k;
  cin >> n >> k;
  int p[1005];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  double ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (double)(((1 + p[i]) * p[i]) / 2) / p[i];
    q[i] = ans;
  }

  double sum = 0;
  for (int i = 0; i < k; i++) {
    sum += q[i];
  }
  double max = sum;
  double kai = 0;
  for (int i = k; i < n; i++) {
    kai = (sum - q[i - k]) + q[i];
    if (max < kai) {
      max = kai;
    }
    sum = kai;
  }
  printf("%.12f", max);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  int n, k;
  cin >> n >> k;
  int p[200005];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  double ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (double)(((1 + p[i]) * p[i]) / 2) / p[i];
    q[i] = ans;
  }

  double sum = 0;
  for (int i = 0; i < k; i++) {
    sum += q[i];
  }
  double max = sum;
  double kai = 0;
  for (int i = k; i < n; i++) {
    kai = (sum - q[i - k]) + q[i];
    if (max < kai) {
      max = kai;
    }
    sum = kai;
  }
  printf("%.12f", max);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll a, b, c, d = 0, e = 1, i, j, k, l;
  cin >> a >> d;
  vector<double> v, vv;
  double x, y, z;
  for (i = 1; i <= a; i++) {
    cin >> x;
    v.push_back(x);
  }

  for (i = 0; i < a; i++) {
    x = v[i];
    y = ((x / 2.0) * (x + 1)) / x;
    vv.push_back(y);
  }
  x = 0.0;
  z = 0.0;
  for (i = 0; i + d <= a; i++) {
    for (j = i; j < i + d; j++) {
      x += vv[j];
    }
    z = max(z, x);
    x = 0;
  }
  printf("%0.12f\n", z);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll a, b, c, d = 0, e = 1, i, j, k, l;
  cin >> a >> d;
  vector<double> v, vv;
  double x, y, z;
  for (i = 1; i <= a; i++) {
    cin >> x;
    v.push_back(x);
  }

  for (i = 0; i < a; i++) {
    x = v[i];
    y = ((x / 2.0) * (x + 1)) / x;
    vv.push_back(y);
  }
  x = 0.0;
  z = 0.0;
  for (i = 0; i < d; i++) {
    x += vv[i];
  }
  z = max(z, x); // cout<<z<<endl;
  for (i = d, j = 0; i < a; i++, j++) {

    x = x + vv[i] - vv[j];
    // cout<<x<<" "<<v[j]<<endl;
    z = max(x, z);
  }
  printf("%0.12f\n", z);
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P>> G;
void g_dir(G &graph, ll a, ll b, ll w = 1) { graph[a].push_back(P(b, w)); }
void g_undir(G &graph, ll a, ll b, ll w = 1) {
  g_dir(graph, a, b, w);
  g_dir(graph, b, a, w);
}
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; (i)--)
template <class T> void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll p[1010];
double v[1010];

int main() {

  ll N, K;
  cin >> N >> K;
  rep1(i, N) {
    cin >> p[i];
    v[i] = p[i] * (p[i] + 1) / 2.0 / p[i];
    v[i] += v[i - 1];
  }
  double ans = 0;
  rep1(i, N) {
    ll j = i - K;
    if (j < 0)
      continue;
    chmax(ans, v[i] - v[j]);
  }
  printf("%.10f\n", ans);

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P>> G;
void g_dir(G &graph, ll a, ll b, ll w = 1) { graph[a].push_back(P(b, w)); }
void g_undir(G &graph, ll a, ll b, ll w = 1) {
  g_dir(graph, a, b, w);
  g_dir(graph, b, a, w);
}
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; (i)--)
template <class T> void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll p[202020];
double v[202020];

int main() {

  ll N, K;
  cin >> N >> K;
  rep1(i, N) {
    cin >> p[i];
    v[i] = p[i] * (p[i] + 1) / 2.0 / p[i];
    v[i] += v[i - 1];
  }
  double ans = 0;
  rep1(i, N) {
    ll j = i - K;
    if (j < 0)
      continue;
    chmax(ans, v[i] - v[j]);
  }
  printf("%.10f\n", ans);

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define range(i, l, r) for (int i = l; i < (int)(r); ++i)
#define rrange(i, l, r) for (int i = r - 1; i >= (int)(l); --i)
#define unless(a) if (!(a))
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi = vector<int>;
using pii = pair<int, int>;
using ll = long long;

template <typename T> bool chmin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <typename T> bool chmax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
// int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

const int inf = TEN(18) * 3 + 10;
const int mod = TEN(9) + 7;

int N, K;

signed main() {
  cin >> N >> K;
  vector<double> a(N + 1), rui(N + 1);
  rep(i, N) {
    int p;
    cin >> p;
    a[i + 1] = (p + 1) / 2.0;
  }

  rep(i, N) { rui[i + 1] += rui[i] + a[i + 1]; }

  double ans = 0;

  rep1(i, N) { chmax(ans, rui[i + K - 1] - rui[i - 1]); }

  printf("%.10f\n", ans);
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define range(i, l, r) for (int i = l; i < (int)(r); ++i)
#define rrange(i, l, r) for (int i = r - 1; i >= (int)(l); --i)
#define unless(a) if (!(a))
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi = vector<int>;
using pii = pair<int, int>;
using ll = long long;

template <typename T> bool chmin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <typename T> bool chmax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
// int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

const int inf = TEN(18) * 3 + 10;
const int mod = TEN(9) + 7;

int N, K;

signed main() {
  cin >> N >> K;
  vector<double> a(N + 1), rui(N + 1);
  rep(i, N) {
    int p;
    cin >> p;
    a[i + 1] = (p + 1) / 2.0;
  }

  rep(i, N) { rui[i + 1] += rui[i] + a[i + 1]; }

  double ans = 0;

  rep1(i, N) {
    if (i + K - 1 <= N)
      chmax(ans, rui[i + K - 1] - rui[i - 1]);
  }

  printf("%.10f\n", ans);
}