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

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

int main() {
  int n, k;
  double p;
  cin >> n >> k;
  vector<double> v(n + 1, 0);
  double sofar = 0;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    sofar += (p + 1) / 2;
    v[i] = sofar;
  }
  // for(auto x: v) cout << x << " ";
  cout << endl;
  double maxi = 0;
  for (int i = 0; i < n - 2; i++) {
    maxi = max(maxi, v[i + k] - v[i]);
  }
  cout << setprecision(10) << maxi;
}


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

int main() {
  int n, k;
  double p;
  cin >> n >> k;
  vector<double> v(n + 1, 0);
  double sofar = 0;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    sofar += (p + 1) / 2;
    v[i] = sofar;
  }
  // for(auto x: v) cout << x << " ";
  cout << endl;
  double maxi = 0;
  for (int i = 0; i < n - k + 1; i++) {
    // cout << i - (n-1) << endl;
    maxi = max(maxi, v[i + k] - v[i]);
  }
  cout << setprecision(10) << maxi;
}
Problem p02780 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int maxsum = 0;
  for (int i = 0; i < N - K + 1; i++) {
    int partsum = 0;
    for (int j = 0; j < K; j++) {
      partsum += p[i + j];
    }
    if (partsum > maxsum)
      maxsum = partsum;
  }
  cout << setprecision(10) << (maxsum + K) / 2.0 << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int maxsum = 0;
  for (int j = 0; j < K; j++) {
    maxsum += p[j];
  }
  int partsum = maxsum;
  for (int i = 0; i < N - K; i++) {
    partsum += p[i + K] - p[i];
    if (partsum > maxsum)
      maxsum = partsum;
  }
  cout << setprecision(10) << (maxsum + K) / 2.0 << endl;
}
Problem p02780 (C++)

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

int main() {
  long int n, k;
  double ans = 0;
  cin >> n >> k;
  vector<double> a(n), b(n), c(n - k + 1, 0.0); /*期待値の配列b*/
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = (a[i] + 1) / 2;
  }

  for (int i = 0; i < k; i++) {
    c[0] += b[i];
  }

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

  for (int i = 0; i < n; i++) {
    ans = max(ans, c[i]);
  }

  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}

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

int main() {
  long int n, k;
  double ans = 0;
  cin >> n >> k;
  vector<double> a(n), b(n), c(n, 0.0); /*期待値の配列b*/
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = (a[i] + 1) / 2;
  }

  for (int i = 0; i < k; i++) {
    c[0] += b[i];
  }

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

  for (int i = 0; i < n; i++) {
    ans = max(ans, c[i]);
  }

  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}
Problem p02780 (C++)

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  map<int, double> m;
  for (int i = 1; i <= 1000; i++)
    m[i] = (i + 1) / 2.0;
  double mx = 0;
  for (int i = 0; i + k - 1 < n; i++) {
    double tmp = 0;
    for (int j = i; j <= i + k - 1; j++) {
      tmp += m[p[j]];
    }
    mx = max(tmp, mx);
  }
  printf("%.10f\n", mx);
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  map<int, double> m;
  for (int i = 1; i <= 1000; i++)
    m[i] = (i + 1) / 2.0;
  double mx = 0;
  for (int j = 0; j < k; j++) {
    mx += m[p[j]];
  }
  double prev = mx;
  for (int j = 1; j + k - 1 < n; j++) {
    double now = prev - m[p[j - 1]] + m[p[j + k - 1]];
    mx = max(now, mx);
    prev = now;
  }
  printf("%.10f\n", mx);
}
Problem p02780 (C++)

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

using namespace std;
const int LEN = 2e5 + 10;
int p[LEN];
double sum[LEN];

int main() {
  int N, K;
  double ans = 0.0;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
    sum[i] = sum[i - 1] + (1.0 + p[i]) / 2;
  }
  for (int i = 1; i <= N; i++) {
    ans = max(ans, sum[K + i - 1] - sum[i - 1]);
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}

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

using namespace std;
const int LEN = 2e5 + 10;
int p[LEN];
double sum[LEN];

int main() {
  int N, K;
  double ans = 0.0;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
    sum[i] = sum[i - 1] + (1.0 + p[i]) / 2;
  }
  for (int i = 0; i <= N - K; i++) {
    ans = max(ans, sum[K + i] - sum[i]);
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// a<b -> a==b;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  long long N, K, i, p[200001], sum = 0, sum_max = 0, maxi = 0;
  double a, ans = 0;

  cin >> N >> K;

  for (i = 1; i <= N; i++) {
    cin >> p[i];
  }

  // sumの初期化
  for (i = 1; i <= K; i++) {
    sum += p[i];
    if (sum > sum_max) {
      sum_max = sum;
      maxi = i;
    }
  }

  if (K < N) {
    for (i = K + 1; i <= N; i++) {
      sum -= p[i - K];
      sum += p[i];
      if (sum > sum_max) {
        sum_max = sum;
        maxi = i - K + 1;
      }
    }
  }

  for (i = maxi; i <= maxi + K - 1; i++) {
    a = (double)(1 + p[i]) / 2;
    ans += a;
  }

  cout << setprecision(20) << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// a<b -> a==b;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  long long N, K, i, p[200001], sum = 0, sum_max = 0, maxi = 0;
  double a, ans = 0;

  cin >> N >> K;

  for (i = 1; i <= N; i++) {
    cin >> p[i];
  }

  // sumの初期化
  for (i = 1; i <= K; i++) {
    sum += p[i];
    if (sum > sum_max) {
      sum_max = sum;
      maxi = i;
    }
  }

  if (K < N) {
    for (i = K + 1; i <= N; i++) {
      sum -= p[i - K];
      sum += p[i];
      if (sum > sum_max) {
        sum_max = sum;
        maxi = i - K + 1;
      }
    }
  } else {
    maxi = 1;
  }

  for (i = maxi; i <= maxi + K - 1; i++) {
    a = (double)(1 + p[i]) / 2;
    ans += a;
  }

  cout << setprecision(20) << ans << endl;

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>
#define S second
#define int long long
using namespace std;
int x[1000000];
signed main() {
  int a, b, ans = 0;
  cin >> a >> b;
  f(i, a) {
    cin >> x[i + 1];
    x[i + 1] += x[i];
  }
  for (int i = b; i <= a; i++) {
    ans = max(x[i] - x[i - b], ans);
  }
  printf("%.100LF\n", (ans + b) / 2.0);
}


Fixed submission:
#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>
#define S second
#define int long long
using namespace std;
int x[1000000];
signed main() {
  int a, b, ans = 0;
  cin >> a >> b;
  f(i, a) {
    cin >> x[i + 1];
    x[i + 1] += x[i];
  }
  for (int i = b; i <= a; i++) {
    ans = max(x[i] - x[i - b], ans);
  }
  printf("%.100lf\n", (ans + b) / 2.0);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;

  double p[N];
  double expect[N];
  for (int i = 0; i < N; i++)
    cin >> p[i];
  for (int i = 0; i < N; i++) {
    double tmp = 0.0;
    for (int j = 0; j < p[i]; j++) {
      tmp += (j + 1) / p[i];
    }
    expect[i] = tmp;
  }
  double ans = 0;
  for (int i = 0; i <= N - K; i++) {
    double tmp2 = 0.0;
    for (int j = 0; j < K; j++) {
      tmp2 += expect[i + j];
    }
    ans = max(ans, tmp2);
  }

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;

  double p[N];
  double expect[N];
  for (int i = 0; i < N; i++)
    cin >> p[i];
  for (int i = 0; i < N; i++) {
    double tmp = 0.0;
    for (int j = 0; j < p[i]; j++) {
      tmp += (j + 1) / p[i];
    }
    expect[i] = tmp;
  }
  double ans = 0;
  double comsum[N + 1];
  comsum[0] = 0.0;
  for (int i = 0; i < N; i++) {
    comsum[i + 1] = comsum[i] + expect[i];
  }

  for (int i = K; i <= N; i++) {
    double tmp2 = comsum[i] - comsum[i - K];
    ans = max(ans, tmp2);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int N, K;
  double arr[200000];
  double ans = 0;
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    double num;
    scanf("%lf", &num);
    arr[i] = (1.0 + num) / 2;
  }

  for (int i = 0; i < N - K + 1; i++) {
    double ret = 0;
    for (int j = i; j < i + K; j++) {
      ret += arr[j];
    }
    ans = max(ans, ret);
  }

  printf("%lf\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int N, K;
  double arr[200000];
  double ans = 0;
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    double num;
    scanf("%lf", &num);
    arr[i] = (1.0 + num) / 2;
  }
  double ret = 0;
  for (int i = 0; i < K; i++) {
    ret += arr[i];
  }
  ans = max(ans, ret);
  for (int i = K; i < N; i++) {
    ret += (arr[i] - arr[i - K]);
    ans = max(ans, ret);
  }

  printf("%lf\n", ans);
}
Problem p02780 (C++)

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

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

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

int main() {
  int n, k;
  cin >> n >> k;
  double p[n], ans = 0;
  for (int i = 0; i < n; i++) {
    double a;
    cin >> a;
    p[i] = (a + 1) / 2;
  }
  double q[n + 1];
  q[0] = 0;
  for (int i = 0; i < n; i++)
    q[i + 1] = q[i] + p[i];
  for (int i = 0; i + k <= n; i++) {
    ans = max(q[i + k] - q[i], ans);
  }
  cout << fixed << setprecision(10) << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
// g++ -std=c++14 test.cpp -o test.out
#include <algorithm>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

int N, K;
int p[200000];

double ans = 0;

double dice_expected[200000];

void solve() {
  // 各サイコロについて期待値を求める
  for (int i = 0; i < N; i++) {
    dice_expected[i] = (p[i] + 1) * p[i] / 2;
    dice_expected[i] = (dice_expected[i] / (double)p[i]);
  }
  // それからどの隣接するK個のサイコロがいいかを調べる
  for (int i = 0; i <= N - K; i++) {
    double expected_sum = 0;
    for (int k = i; k < i + K; k++) {
      double expected = 0;
      expected_sum += dice_expected[k];
    }
    if (ans < expected_sum)
      ans = expected_sum;
  }
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> p[i];

  solve();

  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Fixed submission:
// g++ -std=c++14 test.cpp -o test.out
#include <algorithm>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

int N, K;
int p[200000];

double ans = 0;

double dice_expected[200000];

void solve() {
  // 各サイコロについて期待値を求める
  for (int i = 0; i < N; i++) {
    dice_expected[i] = (p[i] + 1) * p[i] / 2;
    dice_expected[i] = (dice_expected[i] / (double)p[i]);
  }
  // それからどの隣接するK個のサイコロがいいかを調べる
  double expected_sum = 0;
  for (int i = 0; i < K; i++) {
    expected_sum += dice_expected[i];
  }
  ans = expected_sum;
  for (int i = K; i < N; i++) {
    expected_sum -= dice_expected[i - K];
    expected_sum += dice_expected[i];
    if (expected_sum > ans)
      ans = expected_sum;
  }
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> p[i];

  solve();

  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
Problem p02780 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);
  vector<double> kitai(N - K + 1, 0.0);

  for (int i = 0; i < kitai.size(); i++) {
    for (int j = 0; j < K; j++) {
      kitai.at(i) += (p.at(i + j) + 1) / 2;
    }
  }

  double ans = 0.0;
  for (auto i : kitai) {
    if (i > ans)
      ans = i;
  }

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

  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);
  vector<double> kitai(N - K + 1, 0.0);

  for (int i = 0; i < K; i++) {
    kitai.at(0) += (p.at(i) + 1) / 2;
  }

  for (int i = 1; i < kitai.size(); i++) {
    kitai.at(i) =
        kitai.at(i - 1) + (p.at(i + K - 1) + 1) / 2 - (p.at(i - 1) + 1) / 2;
  }

  double ans = 0.0;
  for (auto i : kitai) {
    if (i > ans)
      ans = i;
  }

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

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
int main(int argc, char *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  vector<double> r(n + 1);
  r[0] = 0;
  double ans = 0;
  for (int i = 1; i < n + 1; i++) {
    r[i] = 1 / 2.0 * (p[i - 1] + 1);
  }
  for (int i = 1; i < n + 1; i++) {
    r[i] += r[i - 1];
  }
  for (int i = 1; i < n + 1; i++) {
    double e;
    e = r[i + k - 1] - r[i - 1];
    if (ans < e)
      ans = e;
  }

  cout << setprecision(10) << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
int main(int argc, char *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  vector<double> r(n + 1);
  r[0] = 0;
  double ans = 0;
  for (int i = 1; i < n + 1; i++) {
    r[i] = 1 / 2.0 * (p[i - 1] + 1);
  }
  for (int i = 1; i < n + 1; i++) {
    r[i] += r[i - 1];
  }
  for (int i = 1; i < n - k + 2; i++) {
    double e;
    e = r[i + k - 1] - r[i - 1];
    if (ans < e)
      ans = e;
  }

  cout << setprecision(10) << ans << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
// p面体サイコロの期待値
// (p+1)/2 // 7なら4 // 6なら3.5

// 期待値の配列を用意
//   vector<int> exp(n);

// 連続するK個の合計期待値は、
// exp(0)+exp(1)+...+exp(K-1)
// から始まって、K-1=Nとなるまで、異なる選び方ができる

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

int main() {

  int K, N;
  int num = 0;
  cin >> N >> K;
  vector<double> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> num;
    vec.at(i) = ((double)num + 1) / 2;
  }

  double sum = 0.0;
  double maxExp = 0.0;
  for (int i = 0; i + K <= N; i++) {
    sum = 0.0;
    for (int j = i; j < i + K; j++) {
      sum += vec.at(j);
    }
    if (sum > maxExp) {
      maxExp = sum;
    }
  }

  cout << fixed << setprecision(12) << maxExp << endl;
  return 0;
}

Fixed submission:
// p面体サイコロの期待値
// (p+1)/2 // 7なら4 // 6なら3.5

// 期待値の配列を用意
//   vector<int> exp(n);

// 連続するK個の合計期待値は、
// exp(0)+exp(1)+...+exp(K-1)
// から始まって、K-1=Nとなるまで、異なる選び方ができる

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

int main() {

  int K, N;
  int num = 0;
  cin >> N >> K;
  vector<double> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> num;
    vec.at(i) = ((double)num + 1) / 2;
  }

  double sum = 0.0;
  double maxExp = 0.0;
  for (int i = 0; i < K; i++) {
    sum += vec.at(i);
  }
  maxExp = sum;

  if (N > 1) {
    for (int i = 0; i < N - K; i++) {
      sum = sum - vec.at(i) + vec.at(i + K);
      if (sum > maxExp) {
        maxExp = sum;
      }
    }
  }

  cout << fixed << setprecision(12) << maxExp << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define repk(i, m, n) for (ll i = m; i < n; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD = 1e9 + 7;
ll sum[200005] = {0};
int main() {
  ll n, k, temp, maxx = 0;
  cin >> n >> k;
  rep1(i, n) {
    cin >> temp;
    sum[i] = sum[i - 1] + temp;
  }
  rep(i, k + 1) { maxx = max(maxx, sum[i + k] - sum[i]); }
  maxx += k;
  cout << maxx / 2;
  if (maxx % 2 == 1)
    cout << ".5";
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define repk(i, m, n) for (ll i = m; i < n; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD = 1e9 + 7;
ll sum[200005] = {0};
int main() {
  ll n, k, temp, maxx = 0;
  cin >> n >> k;
  rep1(i, n) {
    cin >> temp;
    sum[i] = sum[i - 1] + temp;
  }
  rep(i, n - k + 1) { maxx = max(maxx, sum[i + k] - sum[i]); }
  maxx += k;
  cout << maxx / 2;
  if (maxx % 2 == 1)
    cout << ".5";
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <bitset>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
typedef long long ll;
using namespace std;

int main(int argc, const char *argv[]) {

  // input from txt （提出時にこの箇所は削除すること）
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());

  ll N, K;
  cin >> N >> K;
  vector<double> s(N + 1);
  s[0] = 0;
  vector<double> p(N + 1);
  p[0] = 0;
  for (ll i = 0; i < N; i++) {
    cin >> p[i + 1];
    s[i + 1] = s[i] + p[i + 1];
  }

  ll max_expect = 0;
  ll i_save = 0;
  ;
  for (ll i = 1; i <= N - K + 1; i++) {
    if (max_expect < s[i + K - 1] - s[i - 1]) {
      max_expect = s[i + K - 1] - s[i - 1];
      i_save = i;
    }
  }
  double sum = 0.0;
  for (ll i = 0; i < K; i++) {
    //        cout << "p[i_save] : " << p[i_save+i] << endl;
    //        sum += (p[i_save+i] + 1.0) / 2.0;
    sum += p[i_save + i] + 1.0;
  }
  sum /= 2.0;
  cout << setprecision(10) << sum << endl;
  //    cout << "save_i : " << i_save << endl;

  return 0;
}


Fixed submission:
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <bitset>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
typedef long long ll;
using namespace std;

int main(int argc, const char *argv[]) {

  //    // input from txt （提出時にこの箇所は削除すること）
  //    std::ifstream in("input.txt");
  //    std::cin.rdbuf(in.rdbuf());
  //
  ll N, K;
  cin >> N >> K;
  vector<double> s(N + 1);
  s[0] = 0;
  vector<double> p(N + 1);
  p[0] = 0;
  for (ll i = 0; i < N; i++) {
    cin >> p[i + 1];
    s[i + 1] = s[i] + p[i + 1];
  }

  ll max_expect = 0;
  ll i_save = 0;
  ;
  for (ll i = 1; i <= N - K + 1; i++) {
    if (max_expect < s[i + K - 1] - s[i - 1]) {
      max_expect = s[i + K - 1] - s[i - 1];
      i_save = i;
    }
  }
  double sum = 0.0;
  for (ll i = 0; i < K; i++) {
    //        cout << "p[i_save] : " << p[i_save+i] << endl;
    //        sum += (p[i_save+i] + 1.0) / 2.0;
    sum += p[i_save + i] + 1.0;
  }
  sum /= 2.0;
  cout << setprecision(10) << sum << endl;
  //    cout << "save_i : " << i_save << endl;

  return 0;
}
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++)

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  long double res = 0;
  rep(i, N - K + 1) {
    long double sum = 0;
    for (int j = i; j < i + K; j++) {
      long long d = P[j] * (P[j] + 1) / 2;
      sum += d / (long double)P[j];
    }
    res = max(res, sum);
  }
  cout << setprecision(12) << res << endl;

  return 0;
}

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

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  vector<long double> D(N);
  rep(i, N) {
    long long d = P[i] * (P[i] + 1) / 2;
    D[i] = d / (long double)P[i];
  }
  long double sum = 0;
  rep(i, K) sum += D[i];
  long double res = sum;
  rep(i, N - K) {
    sum += D[i + K];
    sum -= D[i];
    res = max(res, sum);
  }
  cout << setprecision(12) << res << endl;

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  long double a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  long double ans = 0, temp = 0;
  for (int j = 0; j < n - k + 1; j++) {
    temp = 0;
    for (int i = 0; i < k; i++) {
      temp += (a[i + j] / 2) + 0.5;
    }
    ans = max(temp, ans);
  }
  cout << fixed << setprecision(12);
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  long double a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  long double ans = 0, temp = 0;
  for (int i = 0; i < k; i++) {
    ans += (a[i] / 2) + 0.5;
  }
  temp = ans;
  for (int i = k; i < n; i++) {
    temp -= (a[i - k] / 2) + 0.5;
    temp += (a[i] / 2) + 0.5;
    ans = max(temp, ans);
  }
  cout << fixed << setprecision(12);
  cout << ans;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  double expect[1005];

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int data;
    cin >> data;
    expect[i] = (data + 1) / 2.0;
  }

  // 左からk個のサイコロの期待値を計算する
  double sum = 0;
  for (int i = 0; i < k; i++) {
    sum += expect[i];
  }
  // 左のサイコロを引き、右のサイコロを足しながらiを進める
  double maxim = sum;
  for (int i = 0; i < n - k; i++) {
    sum = sum - expect[i] + expect[i + k];
    maxim = max(maxim, sum);
  }

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

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  double expect[200005];

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int data;
    cin >> data;
    expect[i] = (data + 1) / 2.0;
  }

  // 左からk個のサイコロの期待値を計算する
  double sum = 0;
  for (int i = 0; i < k; i++) {
    sum += expect[i];
  }
  // 左のサイコロを引き、右のサイコロを足しながらiを進める
  double maxim = sum;
  for (int i = 0; i < n - k; i++) {
    sum = sum - expect[i] + expect[i + k];
    maxim = max(maxim, sum);
  }

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

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int N, K;
  double p[1000];
  cin >> N >> K;

  double total = 0;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    p[i] = (double)(1 + tmp) / 2;
    if (i < K)
      total += p[i];
  }

  double maxTotal = total;
  for (int i = K; i < N; ++i) {
    total = total - p[i - K] + p[i];
    if (maxTotal < total)
      maxTotal = total;
  }

  printf("%10.10lf", maxTotal);

  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int N, K;
  double *p;
  p = new double[200000];
  cin >> N >> K;

  double total = 0;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    p[i] = (double)(1 + tmp) / 2;
    if (i < K)
      total += p[i];
  }

  double maxTotal = total;
  for (int i = K; i < N; ++i) {
    total = total - p[i - K] + p[i];
    if (maxTotal < total)
      maxTotal = total;
  }

  printf("%10.10lf", maxTotal);

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> ip;
typedef pair<ll, ll> lp;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> exp(N);
  rep(i, N) {
    double t;
    cin >> t;
    exp[i] = t * (t + 1) / 2 / t;
  }
  double ans = 0;
  rep(i, N) exp[i + 1] += exp[i];
  ans = exp[K - 1];
  for (int i = K; i < N; ++i) {
    ans = max(ans, exp[i] - exp[i - K]);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> ip;
typedef pair<ll, ll> lp;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> exp(N);
  rep(i, N) {
    double t;
    cin >> t;
    exp[i] = t * (t + 1) / 2 / t;
  }
  double ans = 0;
  rep(i, N - 1) exp[i + 1] += exp[i];
  ans = exp[K - 1];
  for (int i = K; i < N; ++i) {
    ans = max(ans, exp[i] - exp[i - K]);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
// g++ -std=gnu++1y -O2 xxx.cpp

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> pi(K);
  vector<double> e(K);
  vector<double> sum(K);

  for (int i = 0; i < K; i++) {
    cin >> pi[i];
  }

  // 期待値計算
  for (int i = 0; i < K; i++) {
    e[i] = (1.0 / pi[i]) * (1.0 / 2.0) * (pi[i] + 1) * (pi[i] + 1 - 1);
    // cout << e[i] << " ";
  }

  for (int i = 0; i <= K - N; i++) {
    for (int j = 0; j < N; j++) {
      sum[i] += e[i + j];
    }
  }

  sort(sum.begin(), sum.end(), greater<int>());

  cout << setprecision(16) << sum[0] << endl;

  return 0;
}

Fixed submission:
// g++ -std=gnu++1y -O2 xxx.cpp

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> pi(K);
  vector<double> e(K);
  vector<double> sum(K);

  for (int i = 0; i < K; i++) {
    cin >> pi[i];
  }

  // 期待値計算
  for (int i = 0; i < K; i++) {
    e[i] = (1.0 / pi[i]) * (1.0 / 2.0) * (pi[i] + 1) * (pi[i] + 1 - 1);
    // cout << e[i] << " ";
  }

  for (int j = 0; j < N; j++) {
    sum[0] += e[0 + j];
  }

  for (int i = 1; i <= K - N; i++) {
    sum[i] = sum[i - 1] - e[i - 1] + e[i + N - 1];
  }

  sort(sum.begin(), sum.end(), greater<int>());

  cout << setprecision(16) << sum[0] << endl;

  return 0;
}
Problem p02780 (C++)

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

using namespace std;
const int N = 2e2 + 10;
typedef long long ll;

int a[N];
ll sum[N];
int cmp(int a, int b) { return a > b; }
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i != 0)
      sum[i] = sum[i - 1] + a[i];
    else
      sum[i] = a[i];
  }
  double d = 0;

  for (int i = k; i <= n; i++) {
    double t = sum[i] - sum[i - k];
    d = max((t + k) / 2, d);
  }

  printf("%.9lf", d);

  return 0;
}

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

using namespace std;
const int N = 2e5 + 10;
typedef long long ll;

int a[N];
ll sum[N];
int cmp(int a, int b) { return a > b; }
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i != 0)
      sum[i] = sum[i - 1] + a[i];
    else
      sum[i] = a[i];
  }
  double d = 0;

  for (int i = k; i <= n; i++) {
    double t = sum[i] - sum[i - k];
    d = max((t + k) / 2, d);
  }

  printf("%.9lf", d);

  return 0;
}
Problem p02780 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> ev(n);
  rep(i, n) {
    cin >> ev[i];
    ev[i] = (1 + ev[i]) / (double)2;
  }
  int l;
  double ans = 0.0, tmp = 0.0;
  rep(i, n) {
    if (i - l < k) {
      tmp += ev[i];
    } else {
      tmp -= ev[l];
      tmp += ev[i];
      l++;
    }
    ans = max(ans, tmp);
  }
  printf("%.12f\n", ans);
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> ev(n);
  rep(i, n) {
    cin >> ev[i];
    ev[i] = (1 + ev[i]) / (double)2;
  }
  int l = 0;
  double ans = 0.0, tmp = 0.0;
  rep(i, n) {
    if (i - l < k) {
      tmp += ev[i];
    } else {
      tmp -= ev[l];
      tmp += ev[i];
      l++;
    }
    ans = max(ans, tmp);
  }
  printf("%.12f\n", ans);
}
Problem p02780 (C++)

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

using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  double *p = new double[n];
  double *E = new double[n];
  double sum = 0;
  double maxsum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", p[i]);
  }

  for (int i = 0; i < n; i++) {
    E[i] = (1 + p[i]) / 2;
  }
  for (int i = 0; i < k; i++) {
    sum += E[i];
  }
  maxsum = sum;
  for (int i = 0; i < n - k; i++) {
    sum = sum - E[i] + E[i + k];
    maxsum = max(maxsum, sum);
  }

  cout << setprecision(10) << maxsum << endl;
  delete[] p, E;
  return 0;
}

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

using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  double *p = new double[n];
  double *E = new double[n];
  double sum = 0;
  double maxsum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lf", &p[i]);
  }

  for (int i = 0; i < n; i++) {
    E[i] = (1 + p[i]) / 2;
  }
  for (int i = 0; i < k; i++) {
    sum += E[i];
  }
  maxsum = sum;
  for (int i = 0; i < n - k; i++) {
    sum = sum - E[i] + E[i + k];
    maxsum = max(maxsum, sum);
  }

  cout << setprecision(10) << maxsum << endl;
  delete[] p, E;
  return 0;
}
Problem p02780 (C++)

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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);

  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }

  int maxval = 0;
  for (int i = 0; i < N - K + 1; i++) {
    int val = 0;
    for (int j = i; j < i + K; j++) {
      val += 1 + p[j];
    }
    if (val > maxval)
      maxval = val;
  }

  double E = maxval * 0.5;

  cout << std::fixed << std::setprecision(10) << E << endl;
  return 0;
}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);

  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }

  ll maxval = 0;
  ll sum = 0;
  for (int i = 0; i < K; i++) {
    sum += 1 + p[i];
  }
  maxval = sum;

  for (int i = 1; i < N - K + 1; i++) {
    sum = sum - p[i - 1] + p[i + K - 1];
    if (sum > maxval)
      maxval = sum;
  }

  double E = maxval * 0.5;

  cout << std::fixed << std::setprecision(10) << E << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x)                                                                \
  int x;                                                                       \
  cin >> x

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

  vector<double> vp;
  rep(i, n) {
    capi(p);
    vp.push_back((p + 1) / 2.0);
  }

  double ans = 0.0;
  for (int i = 0; i + k <= n; ++i) {
    double res = 0.0;
    rep(j, k) { res += vp[i + j]; }

    ans = max(ans, res);
  }

  printf("%.12lf", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x)                                                                \
  int x;                                                                       \
  cin >> x

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

  vector<double> vp;
  rep(i, n) {
    capi(p);
    vp.push_back((p + 1) / 2.0);
  }

  double res = 0.0;
  rep(j, k) { res += vp[j]; }
  double ans = res;

  for (int i = 0; i + k < n; ++i) {
    res += vp[i + k];
    res -= vp[i];

    ans = max(ans, res);
  }

  printf("%.12lf", ans);

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
long double a[200010];
int main() {
  ll n, k;

  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  long double ch = 0;
  for (ll i = 0; i < k; i++) {
    long double sum = 0;
    sum += (a[i] + 1) / 2.0;
    //		cout << sum<<" "<<i<<endl;
    ch += sum;
  }
  long double ans = ch;
  //	cout << ch<<endl;
  for (ll i = 0; i < n; i++) {
    ch = ch - (a[i] + 1) / 2.0 + (a[i + k] + 1) / 2.0;
    //		cout <<now<<" "<<i<<endl;
    if (ch > ans) {
      ans = ch;
      //			cout << i<<endl;
      //		ansi=i+1;
    }
  }
  //	cout << ansi<<endl;
  printf("%.9Lf", ans);
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
long double a[200010];
int main() {
  ll n, k;

  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  long double ch = 0;
  for (ll i = 0; i < k; i++) {
    long double sum = 0;
    sum += (a[i] + 1) / 2.0;
    //		cout << sum<<" "<<i<<endl;
    ch += sum;
  }
  long double ans = ch;
  //	cout << ch<<endl;
  for (ll i = 0; i < n - k; i++) {
    ch = ch - (a[i] + 1) / 2.0 + (a[i + k] + 1) / 2.0;
    //		cout <<now<<" "<<i<<endl;
    if (ch > ans) {
      ans = ch;
      //			cout << i<<endl;
      //		ansi=i+1;
    }
  }
  //	cout << ansi<<endl;
  printf("%.9Lf", ans);
  // your code goes here
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
double t[200005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &t[i]);
    t[i] = (t[i] + 1) / 2;
  }
  double max1 = 0;
  for (int i = 1; i <= n - m + 1; i++) {
    double sum = 0;
    for (int j = 0; j < m; j++)
      sum += t[i + j];
    if (sum > max1)
      max1 = sum;
  }
  printf("%.12lf\n", max1);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
double t[200005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &t[i]);
    t[i] = (t[i] + 1) / 2;
  }
  double max1, sum;
  for (int i = 0; i < m; i++)
    max1 += t[1 + i];
  sum = max1;
  for (int i = 2; i <= n - m + 1; i++) {
    sum = sum - t[i - 1] + t[i + m - 1];
    max1 = sum > max1 ? sum : max1;
  }
  printf("%.12lf\n", max1);

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
int mode = 1e9 + 7;
double e[200020];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  double maxn = -1;
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    e[i] = (a * (a + 1) / 2.0) * 1.0 / a;
  }
  for (int i = 0; i < n - k + 1; i++) {
    double sum = 0;
    for (int j = i; j < i + k; j++) {
      sum += e[j];
    }
    if (sum > maxn) {
      maxn = sum;
    }
  }
  printf("%.12lf\n", maxn);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
int mode = 1e9 + 7;
double e[200020];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  double maxn = -1;
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    e[i] = (a * (a + 1) / 2.0) * 1.0 / a;
  }
  double sum = 0;
  for (int i = 0; i < k; i++) {
    sum += e[i];
  }
  //	cout<<sum<<endl;
  int i = 0, j = k;
  while (1) {
    maxn = max(sum, maxn);
    // cout<<maxn<<" ";
    sum = sum + e[j] - e[i];
    i++;
    j++;
    if (j > n) {
      break;
    }
  }
  printf("%.12lf\n", maxn);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> p(N);
  rep(i, N) cin >> p[i];

  vector<double> e(N);
  rep(i, N) { e[i] = ((double)p[i] * (1 + p[i]) / 2) / p[i]; }

  // rep(i, N) cout << e[i] << " ";
  // cout << endl;

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

  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> p(N);
  rep(i, N) cin >> p[i];

  vector<double> e(N);
  rep(i, N) { e[i] = ((double)p[i] * (1 + p[i]) / 2) / p[i]; }

  // rep(i, N) cout << e[i] << " ";
  // cout << endl;

  double current = 0.0;

  rep(i, K) { current += e[i]; }
  double ans = current;

  reps(i, K, N) {
    current = current - e[i - K] + e[i];
    // cout << current << endl;
    ans = max(current, ans);
  }

  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}
Problem p02780 (C++)

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REP3(i, st, en) for (ll(i) = (st); (i) < (en); (i)++)

using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<double> p(N);
  REP(i, N) { cin >> p[i]; }

  ll left = 0;
  ll sum = 0;
  REP(i, K) { sum += p[i]; }
  ll maxv = sum;
  REP3(i, 1, N - K + 1) {
    sum += p[i];
    sum -= p[i - K];
    if (sum > maxv) {
      left = i;
      maxv = sum;
    }
  }

  double ans = 0;
  REP(i, K) { ans += (p[left + i] + 1.0) / 2; }
  cout << fixed << setprecision(10) << ans << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;

typedef long long ll;

#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REP3(i, st, en) for (ll(i) = (st); (i) < (en); (i)++)

using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<double> p(N);
  REP(i, N) { cin >> p[i]; }

  ll left = 0;
  ll sum = 0;
  REP(i, K) { sum += p[i]; }
  ll maxv = sum;
  REP3(i, 1, N - K + 1) {
    sum -= p[i - 1];
    sum += p[i + K - 1];
    if (sum > maxv) {
      left = i;
      maxv = sum;
    }
  }

  double ans = 0;
  REP(i, K) { ans += (p[left + i] + 1.0) / 2; }
  cout << fixed << setprecision(10) << ans << "\n";
  return 0;
}
Problem p02780 (C++)

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

bool cmp(double a, double b) { return a > b; }

int main() {
  int n, k;
  double aa[1005];
  double bb[20005];
  double cc[20005] = {0};
  cin >> n >> k;
  aa[1] = 1;
  for (int i = 2; i <= 1000; i++) {
    if (i % 2 == 0)
      aa[i] = i / 2 + 0.5;
    else
      aa[i] = i / 2 + 1;
  }
  int t;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    bb[i] = aa[t];
  }
  for (int i = 1; i <= k; i++) {
    cc[1] += bb[i];
  }
  for (int i = 2; i <= n - k + 1; i++) {
    cc[i] = cc[i - 1] - bb[i - 1] + bb[i + k - 1];
  }
  sort(cc + 1, cc + 1 + n - k + 1, cmp);
  printf("%lf", cc[1]);
  return 0;
}


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

bool cmp(double a, double b) { return a > b; }

int main() {
  int n, k;
  double aa[1005];
  double bb[200005];
  double cc[200005] = {0};
  cin >> n >> k;
  aa[1] = 1;
  for (int i = 2; i <= 1000; i++) {
    if (i % 2 == 0)
      aa[i] = i / 2 + 0.5;
    else
      aa[i] = i / 2 + 1;
  }
  int t;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    bb[i] = aa[t];
  }
  for (int i = 1; i <= k; i++) {
    cc[1] += bb[i];
  }
  for (int i = 2; i <= n - k + 1; i++) {
    cc[i] = cc[i - 1] - bb[i - 1] + bb[i + k - 1];
  }
  sort(cc + 1, cc + 1 + n - k + 1, cmp);
  printf("%lf", cc[1]);
  return 0;
}
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++)
#define rep2(i, n) for (int i = 1; i < (n); i++)
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  vector<double> q(n - k + 1, 0);
  rep(i, n - k + 1) {
    rep(j, k) { q[i] += p[i + j]; }
  }
  double ans = 0;
  rep(i, n - k + 1) { ans = max(ans, q[i]); }
  cout << fixed << setprecision(8) << (ans + k) / 2 << endl;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  vector<double> q(n - k + 1, 0);
  rep(j, k) { q[0] += p[j]; }
  rep2(i, n - k + 1) { q[i] = q[i - 1] - p[i - 1] + p[i + k - 1]; }
  double ans = 0;
  rep(i, n - k + 1) { ans = max(ans, q[i]); }
  cout << fixed << setprecision(8) << (ans + k) / 2 << endl;
}