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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

long double P[200010];
long double sum[200010];

int main(int argc, char **argv) {
  ll N, K;
  cin >> N >> K;
  for (ll i = 0; i < N; ++i) {
    long double p;
    cin >> p;
    P[i] = (p * (1 + p) / 2) / p;
  }

  sum[0] = 0.0;
  for (ll i = 0; i < N; ++i)
    sum[i + 1] = sum[i] + P[i];

  long double res{0.0};
  for (ll i = 0; i < N + K - 1; ++i) {
    res = max(res, sum[i + K] - sum[i]);
  }

  std::cout << fixed << setprecision(10) << res << std::endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

long double P[200010];
long double sum[200010];

int main(int argc, char **argv) {
  ll N, K;
  cin >> N >> K;
  for (ll i = 0; i < N; ++i) {
    long double p;
    cin >> p;
    P[i] = (p * (1 + p) / 2) / p;
  }

  sum[0] = 0.0;
  for (ll i = 0; i < N; ++i)
    sum[i + 1] = sum[i] + P[i];

  long double res{0.0};
  for (ll i = 0; i < N - K + 1; ++i) {
    res = max(res, sum[i + K] - sum[i]);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
ll p[200010];
int main() {
  ll N, K;
  cin >> N >> K;
  rep(i, N) { cin >> p[i]; }

  ll tmpmax = -INF;
  ll tmp;
  for (ll i = 0; i <= N - K; i++) {
    tmp = 0;
    rep(j, K) { tmp += p[i + j]; }
    if (tmp > tmpmax) {
      tmpmax = tmp;
    }
  }

  double result = (tmpmax + K) / 2.0;

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
ll p[200010];
int main() {
  ll N, K;
  cin >> N >> K;
  rep(i, N) { cin >> p[i]; }

  ll tmpmax = -INF;
  ll tmp = 0;
  ll a = p[0];
  ll b = p[K - 1];

  rep(i, K) { tmp += p[i]; }
  tmpmax = tmp;

  for (ll i = 0; i < N - K; i++) {
    tmp -= a;
    a = p[i + 1];
    b = p[i + K];
    tmp += b;
    if (tmp > tmpmax) {
      tmpmax = tmp;
    }
  }

  double result = (tmpmax + K) / 2.0;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll, ll> P;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    vec.at(i) = (1 + vec.at(i)) * vec.at(i) / 2 / vec.at(i);
  }
  double ret = 0;
  for (int i = 0; i < N - K + 1; i++) {
    double cnt = 0;
    for (int j = 0; j < K; j++) {
      cnt += vec.at(i + j);
    }
    ret = max(ret, cnt);
  }
  cout << fixed;
  cout << setprecision(10) << ret << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll, ll> P;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    vec.at(i) = (1 + vec.at(i)) * vec.at(i) / 2 / vec.at(i);
  }
  double ret = 0;
  double cnt = 0;
  for (int i = 0; i < K; i++) {
    ret += vec.at(i);
    cnt += vec.at(i);
  }
  for (int i = K; i < N; i++) {
    cnt -= vec.at(i - K);
    cnt += vec.at(i);
    ret = max(ret, cnt);
  }
  cout << fixed;
  cout << setprecision(10) << ret << endl;
}
Problem p02780 (C++)

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

double a[200020];
int sum[1010];
int main() {
  for (int i = 1; i <= 1000; i++) {
    sum[i] = sum[i - 1] + i;
  }
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%lf", &a[i]);
    a[i] = sum[(int)a[i]] / a[i];
  }
  double ans = 0, t = 0;
  for (int i = 0; i < n; i++) {
    int j = i;
    t = 0;
    while (j < n && j - i < k)
      t += a[j], j++;
    ans = max(ans, t);
  }
  printf("%.12lf\n", ans);
  return 0;
}

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

double a[200020];
int sum[1010];
int main() {
  for (int i = 1; i <= 1000; i++) {
    sum[i] = sum[i - 1] + i;
  }
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%lf", &a[i]);
    a[i] = sum[(int)a[i]] / a[i];
  }
  double ans = 0, t = 0;
  int i = 0, j = 0;
  while (j < k)
    t += a[j], j++;
  ans = max(ans, t);
  while (i < n && j < n) {
    t += a[j];
    t -= a[i];
    i++, j++;
    ans = max(ans, t);
  }
  printf("%.12lf\n", ans);
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
// default
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double, double> P_d;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define alrep(i, j, n)                                                         \
  for (int i = 0; i < (n); ++i)                                                \
    for (int j = i + 1; j < (n); ++j)
#define Yes cout << "Yes" << endl;
#define No                                                                     \
  cout << "No" << endl;                                                        \
  int ans = 0;
#define answer cout << ans << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;

signed main() {
  int N, K;
  double ans = -1;
  cin >> N >> K;
  double p[N];
  rep(i, N) { cin >> p[i]; }
  rep(i, N - K + 1) {
    double res = 0;
    for (int j = i; j < i + K; j++) {
      res += (double)(p[j] + 1) / (double)2;
    }
    chmax(ans, res);
  }
  cout << fixed << setprecision(6) << ans << endl;
  return 0;
}


Fixed submission:
// default
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double, double> P_d;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define alrep(i, j, n)                                                         \
  for (int i = 0; i < (n); ++i)                                                \
    for (int j = i + 1; j < (n); ++j)
#define Yes cout << "Yes" << endl;
#define No                                                                     \
  cout << "No" << endl;                                                        \
  int ans = 0;
#define answer cout << ans << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;

signed main() {
  int N, K;
  double ans = -1;
  cin >> N >> K;
  double p[N];
  rep(i, N) {
    cin >> p[i];
    p[i] = (double)(p[i] + 1) / (double)2;
  }
  double res = 0;
  rep(i, K) { res += p[i]; }
  chmax(ans, res);
  rep(i, N - K) {
    res -= p[i];
    res += p[i + K];
    chmax(ans, res);
  }
  cout << fixed << setprecision(6) << ans << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  int N, K, i, j;
  cin >> N >> K;
  vector<double> q(N);
  int p;
  for (i = 0; i < N; i++) {
    cin >> p;
    for (j = 1; j <= p; j++) {
      q[i] += j;
    }
    q[i] /= p;
  }
  double ans = 0;
  for (i = 0; i <= N - K; i++) {
    double w = 0;
    for (j = i; j < i + K; j++) {
      w += q[j];
    }
    if (ans < w) {
      ans = w;
    }
  }
  printf("%.6f\n", ans);

  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  int N, K, i, j;
  cin >> N >> K;
  vector<double> q(N);
  int p;
  for (i = 0; i < N; i++) {
    cin >> p;
    for (j = 1; j <= p; j++) {
      q[i] += j;
    }
    q[i] /= p;
  }
  double ans = 0;
  double w = 0;
  for (i = 0; i < K; i++) {
    ans += q[i];
  }
  w = ans;
  for (i = K; i < N; i++) {
    w = w + q[i] - q[i - K];
    if (ans < w) {
      ans = w;
    }
  }
  printf("%.6f\n", ans);

  return 0;
}
Problem p02780 (C++)

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

#define pb push_back
#define ff first
#define ss second

const long long MAXN = 1e5 + 10, inf = 1e18 + 21, LG = 20;

int n, k;
double p[MAXN], res;
double ans;

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double a;
    cin >> a;
    p[i] = (a + 1) / 2;
  }

  for (int i = 0; i < k; i++) {
    ans += p[i];
    res += p[i];
  }

  for (int i = k; i < n; i++) {
    res -= p[i - k];
    res += p[i];
    ans = max(res, ans);
  }

  cout << fixed << setprecision(10) << ans << '\n';
  return 0;
}


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

#define pb push_back
#define ff first
#define ss second

const long long MAXN = 2e5 + 10, inf = 1e18 + 21, LG = 20;

int n, k;
double p[MAXN], res;
double ans;

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double a;
    cin >> a;
    p[i] = (a + 1) / 2;
  }

  for (int i = 0; i < k; i++) {
    ans += p[i];
    res += p[i];
  }

  for (int i = k; i < n; i++) {
    res -= p[i - k];
    res += p[i];
    ans = max(res, ans);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  double a = 0;
  double p[n];
  for (int i = 0; i < n; i++) {
    cin >> a;
    p[i] = (1 + a) / 2;
  }

  double max = 0;
  for (int i = 0; i < n - k + 1; i++) {
    double max_b = 0;
    for (int j = 0; j < k; j++) {
      max_b += p[i + j];
    }
    if (max < max_b)
      max = max_b;
  }
  cout << fixed << setprecision(12) << max;
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  double a = 0;
  double p[n];
  for (int i = 0; i < n; i++) {
    cin >> a;
    p[i] = (1 + a) / 2;
  }

  double s[n];
  s[0] = p[0];
  for (int j = 1; j < n; j++) {
    s[j] = p[j] + s[j - 1];
  }
  double max = s[k - 1];
  for (int i = k + 1; i < n; i++) {
    if (max < s[i] - s[i - k])
      max = s[i] - s[i - k];
  }
  cout << fixed << setprecision(12) << max;
  return 0;
}
Problem p02780 (C++)

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

#define ll long long
#define vec vector<ll>
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define f(i, x, n) for (ll i = x; i < n; i++)
#define rf(i, x, n) for (ll i = x; i >= x; i--)
#define all(c) c.begin(), c.end()
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
const ll MAX = LLONG_MAX, MOD = 1000000007, MODA = 1e9 - 1;
const ll MIN = LLONG_MIN;
const long double PI = 3.1415926535;
const ll N = 100009;

int main() {
  fast();
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin >> t;
  while (t--) {
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    f(i, 0, n) cin >> arr[i];
    long double brr[n];
    f(i, 0, n) {
      brr[i] = ((arr[i] + 1) * (1.0)) / (2.0);
      // cout << brr[i] << " ";
    }
    // cout << endl;
    long double ans = -1, sum = 0;
    ll ptr = 0, init = 0;
    f(i, 0, n) {
      sum += brr[i];
      ptr++;
      if (ptr >= k) {
        ans = max(ans, sum);
        sum -= brr[init];
        ptr--;
        init++;
      }
    }
    cout << fixed << setprecision(8) << ans << endl;
  }
  return 0;
}


Fixed submission:
// Garg's Code
#include <bits/stdc++.h>
#include <string.h>
using namespace std;

#define ll long long
#define vec vector<ll>
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define f(i, x, n) for (ll i = x; i < n; i++)
#define rf(i, x, n) for (ll i = x; i >= x; i--)
#define all(c) c.begin(), c.end()
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
const ll MAX = LLONG_MAX, MOD = 1000000007, MODA = 1e9 - 1;
const ll MIN = LLONG_MIN;
const long double PI = 3.1415926535;
const ll N = 100009;

int main() {
  fast();

  ll t = 1;
  // cin >> t;
  while (t--) {
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    f(i, 0, n) cin >> arr[i];
    long double brr[n];
    f(i, 0, n) {
      brr[i] = ((arr[i] + 1) * (1.0)) / (2.0);
      // cout << brr[i] << " ";
    }
    // cout << endl;
    long double ans = -1, sum = 0;
    ll ptr = 0, init = 0;
    f(i, 0, n) {
      sum += brr[i];
      ptr++;
      if (ptr >= k) {
        ans = max(ans, sum);
        sum -= brr[init];
        ptr--;
        init++;
      }
    }
    cout << fixed << setprecision(8) << ans << endl;
  }
  return 0;
}
Problem p02780 (C++)

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;
const int MAXN = 500005;

int n, k;
double a[100005];

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    a[i] = double(x + 1) / 2;
  }
  double exp = 0;
  double maxx = 0;
  for (int i = 0; i < k; i++) {
    exp += a[i];
  }
  maxx = exp;
  for (int i = k; i < n; i++) {
    exp -= a[i - k];
    exp += a[i];
    maxx = max(maxx, exp);
  }
  printf("%.7lf\n", maxx);
  return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;
const int MAXN = 500005;

int n, k;
double a[200005];

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    a[i] = double(x + 1) / 2;
  }
  double exp = 0;
  double maxx = 0;
  for (int i = 0; i < k; i++) {
    exp += a[i];
  }
  maxx = exp;
  for (int i = k; i < n; i++) {
    exp -= a[i - k];
    exp += a[i];
    maxx = max(maxx, exp);
  }
  printf("%.7lf\n", maxx);
  return 0;
}
Problem p02780 (C++)

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

using namespace std;

#define fi first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for (int k = (a); k < (b); ++k)
#define ROF(k, a, b) for (int k = (a); k > (b); --k)
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {

  int n, k;

  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> k;

  vi p(n);

  vector<double> preffix(n);

  preffix[0] = 0;

  FOR(i, 0, n) {

    cin >> p[i];
    preffix[i + 1] = preffix[i] + (p[i] + 1.0) / 2.0;
  }

  double E = 0;

  FOR(i, k - 1, n)
  E = max(E, preffix[i + 1] - preffix[i - k + 1]);

  cout << fixed << setprecision(12) << E << '\n';

  return 0;
}


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

using namespace std;

#define fi first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for (int k = (a); k < (b); ++k)
#define ROF(k, a, b) for (int k = (a); k > (b); --k)
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {

  int n, k;

  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> k;

  vi p(n);

  vector<double> preffix(n + 1);

  preffix[0] = 0;

  FOR(i, 0, n) {

    cin >> p[i];
    preffix[i + 1] = preffix[i] + (p[i] + 1.0) / 2.0;
  }

  double E = 0;

  FOR(i, k - 1, n)
  E = max(E, preffix[i + 1] - preffix[i - k + 1]);

  cout << fixed << setprecision(12) << E << '\n';

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vector<double> P(N + 1, 0.0);
  vector<double> S(N + 1, 0.0);
  REP(i, 1, N + 1) {
    ll p;
    cin >> p;
    P[i] = (1.0 + p) / 2.0;
    S[i] = accumulate(P.begin(), P.begin() + i + 1, 0.0);
  }

  double ans = 0.0;
  for (ll i = 0; i + K <= N; i++) {
    ans = max(ans, S[i + K] - S[i]);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vector<double> P(N + 1, 0.0);
  vector<double> S(N + 1, 0.0);
  REP(i, 1, N + 1) {
    ll p;
    cin >> p;
    P[i] = (1.0 + p) / 2.0;
    S[i] = S[i - 1] + P[i];
  }

  double ans = 0.0;
  for (ll i = 0; i + K <= N; i++) {
    ans = max(ans, S[i + K] - S[i]);
  }
  cout << ans << endl;

  return 0;
}
Problem p02780 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  vector<long long> sum(N);
  sum[0] = p[0];
  for (int i = 0; i < N; i++) {
    sum[i + 1] = sum[i] + p[i];
  }

  long long ans = 0;
  for (int i = 0; i + K <= N; ++i) {
    ans = max(ans, sum[i + K] - sum[i]);
  }
  cout << fixed << setprecision(10) << (double)(ans + K) / 2 << endl;
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  vector<long long> sum(N + 1);
  sum[0] = p[0];
  for (int i = 0; i < N; i++) {
    sum[i + 1] = sum[i] + p[i];
  }

  long long ans = 0;
  for (int i = 0; i + K <= N; ++i) {
    ans = max(ans, sum[i + K] - sum[i]);
  }
  cout << fixed << setprecision(10) << (double)(ans + K) / 2 << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll MAXN = 1e5 + 51;
ll cnt, x;
double res, sum;
double prob[MAXN];
inline ll read() {
  register ll num = 0, neg = 1;
  register char ch = getchar();
  while (!isdigit(ch) && ch != '-') {
    ch = getchar();
  }
  if (ch == '-') {
    neg = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch - '0');
    ch = getchar();
  }
  return num * neg;
}
int main() {
  cnt = read(), x = read();
  for (register int i = 0; i < cnt; i++) {
    prob[i] = 1.0 * (1 + read()) / 2;
  }
  for (register int i = 0; i < x; i++) {
    sum += prob[i];
  }
  res = sum;
  for (register int l = 1, r = x; r < cnt; l++, r++) {
    sum = sum + prob[r] - prob[l - 1];
    res = max(res, sum);
  }
  printf("%.12lf\n", res);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll MAXN = 5e5 + 51;
ll cnt, x;
double res, sum;
double prob[MAXN];
inline ll read() {
  register ll num = 0, neg = 1;
  register char ch = getchar();
  while (!isdigit(ch) && ch != '-') {
    ch = getchar();
  }
  if (ch == '-') {
    neg = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch - '0');
    ch = getchar();
  }
  return num * neg;
}
int main() {
  cnt = read(), x = read();
  for (register int i = 0; i < cnt; i++) {
    prob[i] = 1.0 * (1 + read()) / 2;
  }
  for (register int i = 0; i < x; i++) {
    sum += prob[i];
  }
  res = sum;
  for (register int l = 1, r = x; r < cnt; l++, r++) {
    sum = sum + prob[r] - prob[l - 1];
    res = max(res, sum);
  }
  printf("%.12lf\n", res);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#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 _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(), (v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

double kitai[200100];

int main() {
  ll n, k;
  cin >> n >> k;
  Vl p(n);
  rep(i, 0, n) cin >> p[i];

  double bunsi = 0, bunbo;
  Rep(i, 1, 200000) {
    bunsi += i;
    bunbo = i;
    kitai[i] = bunsi / bunbo;
  }

  double ans = 0.0;
  Rep(i, 0, n - k) {
    double sum = 0.0;
    rep(j, i, i + k) { sum += kitai[p[j]]; }
    ans = max(ans, sum);
  }
  cout << fixed << setprecision(7) << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#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 _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(), (v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

double kitai[200100];

int main() {
  ll n, k;
  cin >> n >> k;
  Vl p(n);
  rep(i, 0, n) cin >> p[i];

  double bunsi = 0, bunbo;
  Rep(i, 1, 200000) {
    bunsi += i;
    bunbo = i;
    kitai[i] = bunsi / bunbo;
  }

  double sum = 0.0;
  rep(i, 0, k) sum += kitai[p[i]];
  double ans = sum;
  rep(i, 0, n - k) {
    sum -= kitai[p[i]];
    sum += kitai[p[i + k]];
    ans = max(ans, sum);
  }
  cout << fixed << setprecision(7) << ans << endl;

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template <typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template <typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template <typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define RREP(i, s, e) for (int i = (int)(s); i >= (int)(e); --i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(), ie = (c).end(); i != ie; ++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9 + 7;

int n, m, k;
string s;

int main() {
  cin >> n >> k;
  Vi v(n);
  REP(i, n) cin >> v[i];

  V<double> ex(1001);
  REP2(i, 1, 1001) {
    double sum = i * (i + 1) / 2;
    ex[i] = sum / i;
  }

  double maxi = 0;
  REP(i, n - k + 1) {
    double a = 0;
    REP(j, k) { a += ex[v[i + j]]; }
    maxi = max(maxi, a);
  }

  printf("%.7f\n", maxi);

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template <typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template <typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template <typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define RREP(i, s, e) for (int i = (int)(s); i >= (int)(e); --i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(), ie = (c).end(); i != ie; ++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9 + 7;

int n, m, k;
string s;

int main() {
  cin >> n >> k;
  Vi v(n);
  REP(i, n) cin >> v[i];

  V<double> ex(1001);
  REP2(i, 1, 1001) {
    double sum = i * (i + 1) / 2;
    ex[i] = sum / i;
  }

  double maxi = 0;
  double tmp = 0;
  REP(i, k) { tmp += ex[v[i]]; }
  maxi = tmp;
  REP2(i, 1, n - k + 1) {
    tmp -= ex[v[i - 1]];
    tmp += ex[v[i + k - 1]];
    maxi = max(maxi, tmp);
  }

  printf("%.7f\n", maxi);

  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  double n, k, t;
  double ma = 0, ans = 0;
  vector<double> p;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> t;
    p.push_back((t + 1) / 2);
  }
  for (int i = 0; i < n - k + 1; i++) {
    double s = 0.0;
    for (int j = i; j < i + k; j++) {
      s += p[j];
    }
    ans = max(ans, s);
  }
  cout << setprecision(10) << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  double n, k, t;
  double ma = 0, ans = 0;
  vector<double> p;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> t;
    p.push_back((t + 1) / 2);
  }
  for (int i = 0; i < k; i++) {
    ma += p[i];
  }
  ans = ma;
  for (int i = k; i < n; i++) {
    ma += p[i] - p[i - k];
    ans = max(ans, ma);
  }
  cout << setprecision(10) << ans << endl;
  return 0;
}
Problem p02780 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); (i) < (n); i++)
#define repe(i, f, n) for (ll i = (f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1LL << 60;
using G = vector<map<int, int>>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> arr(N);
  rep(i, 0, N) cin >> arr[i];
  vector<double> ex(1001);
  for (double i = 1; i < 1001; i++) {
    ex[i] = (1 + i) / 2;
  }

  double comp = 0;
  rep(i, 0, K) { comp += ex[arr[i]]; }

  double ans = comp;
  for (int i = 1; i < N - 2; i++) {
    comp = comp - ex[arr[i - 1]] + ex[arr[K + i - 1]];
    if (ans < comp)
      ans = comp;
  }

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

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

ll INF = 1LL << 60;
using G = vector<map<int, int>>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> arr(N);
  rep(i, 0, N) cin >> arr[i];
  vector<double> ex(1001);
  for (double i = 1; i < 1001; i++) {
    ex[i] = (1 + i) / 2;
  }

  double comp = 0;
  rep(i, 0, K) { comp += ex[arr[i]]; }

  double ans = comp;
  for (int i = 1; i <= N - K; i++) {
    comp = comp - ex[arr[i - 1]] + ex[arr[K + i - 1]];
    if (ans < comp)
      ans = comp;
  }

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

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

int sum(int n) {
  int ans = 0;
  if (n == 1)
    return 1;
  if (n % 2 == 0) {
    ans = (1 + n) * n / 2;
  } else {
    ans = (0 + n) * (n + 1) / 2;
  }

  return ans;
}

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

  double ans = 0;
  vector<double> v(n);
  vector<double> p(n - k, 0);
  for (int i = 0; i < k; ++i)
    cin >> v[i];
  for (int i = 0; i < k; ++i) {
    p[0] += sum(v[i]) / v[i];
  }
  ans = p[0];
  for (int i = k; i < n; ++i) {
    cin >> v[i];
    p[i - k + 1] = p[i - k] - sum(v[i - k]) / v[i - k] + sum(v[i]) / v[i];

    if (ans < p[i - k + 1])
      ans = p[i - k + 1];
  }

  cout << fixed << setprecision(15) << ans << endl;
}

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

int sum(int n) {
  int ans = 0;
  if (n == 1)
    return 1;
  if (n % 2 == 0) {
    ans = (1 + n) * n / 2;
  } else {
    ans = (0 + n) * (n + 1) / 2;
  }

  return ans;
}

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

  double ans = 0;
  vector<double> v(n + 1);
  vector<double> p(n - k + 1, 0);
  for (int i = 0; i < k; ++i)
    cin >> v[i];
  for (int i = 0; i < k; ++i) {
    p[0] += sum(v[i]) / v[i];
  }
  ans = p[0];
  for (int i = k; i < n; ++i) {
    cin >> v[i];
    p[i - k + 1] = p[i - k] - sum(v[i - k]) / v[i - k] + sum(v[i]) / v[i];

    if (ans < p[i - k + 1])
      ans = p[i - k + 1];
  }

  cout << fixed << setprecision(15) << ans << endl;
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <string.h>
#include <vector>

int main() {
  int K, N;
  scanf("%d %d", &N, &K);

  std::vector<double> data(N);

  for (int i = 0; i < N; ++i) {
    int d;
    scanf("%d", &d);
    data[i] = d;

    // 期待値 = ((d + 1) / 2);
    data[i] = (data[i] + 1.0) / 2.0;
  }

  double max = 0.0f;
  for (int i = 0; i < (N - K + 1); ++i) {
    double sum = 0.0;
    for (int j = 0; j < K; ++j) {
      sum += data[j + i];
    }
    if (max < sum) {
      max = sum;
    }
  }

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


Fixed submission:
#include <cstdio>
#include <string.h>
#include <vector>

int main() {
  int K, N;
  scanf("%d %d", &N, &K);

  std::vector<double> data(N);

  for (int i = 0; i < N; ++i) {
    int d;
    scanf("%d", &d);
    data[i] = d;

    // 期待値 = ((d + 1) / 2);
    data[i] = (data[i] + 1.0) / 2.0;
  }

  double current = 0.0;

  int i = 0;
  // K まで進む
  for (; i < K; ++i) {
    current += data[i];
  }
  double max = current;

  // 最初を減らして、最後を追加し、比較する
  for (; i < N; ++i) {
    current -= data[i - K];
    current += data[i];
    if (max < current) {
      max = current;
    }
  }

  printf("%f\n", (float)max);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int N;
  int K;
  double sum = 0;
  double peropero = 0;
  scanf("%d %d", &N, &K);
  int a[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }

  for (int i = 0; i < N - K + 1; i++) {
    sum = 0;
    for (int j = 0; j < K; j++) {
      sum = sum + a[i + j];
    }
    if (sum > peropero) {
      peropero = sum;
    }
  }
  peropero = peropero / 2 + 0.5 * K;
  printf("%lf", peropero);
}

Fixed submission:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int N;
  int K;
  double sum = 0;
  double peropero = 0;
  scanf("%d %d", &N, &K);
  int a[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }

  for (int i = 0; i < K; i++) {
    sum = sum + a[i];
  }
  peropero = sum;
  for (int i = 0; i < N - K; i++) {
    sum = sum - a[i] + a[i + K];
    if (sum > peropero) {
      peropero = sum;
    }
  }
  peropero = peropero / 2 + 0.5 * K;
  printf("%lf", peropero);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cassert>
#include <cstdio>
#include <set>
#include <vector>

#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

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

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

  double ans = 0.0;
  for (int i = 0; i < N - K + 1; i++) {
    double sum = 0.0;
    for (int j = 0; j < K; j++) {
      sum += expectedValue(p[j + i]);
    }
    ans = max(ans, sum);
  }

  // cout << ans << endl;
  printf("%.12f\n", ans);
  return 0;
}


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

#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

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

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

  double sum = 0.0;
  for (int i = 0; i < K; i++) {
    sum += expectedValue(p[i]);
  }
  double ans = sum;
  for (int i = 1; i < N - K + 1; i++) {
    sum -= expectedValue(p[i - 1]);
    sum += expectedValue(p[i + K - 1]);
    ans = max(ans, sum);
  }

  // cout << ans << endl;
  printf("%.12f\n", ans);
  return 0;
}
Problem p02780 (C++)

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

const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;

int p[300000];
double sum[300000];

int main() {
  int n, K;
  cin >> n >> K;
  rep(i, n) {
    scanf("%d", &p[i]);
    sum[i] = (1 + p[i]) * p[i] / 2 / (double)p[i];
    if (i)
      sum[i] += sum[i - 1];
  }
  double Max = 0;
  rep(i, n) {
    if (i == K - 1)
      Max = max(Max, sum[i]);
    else
      Max = max(Max, sum[i] - sum[i - K]);
  }
  printf("%.12lf\n", Max);
}

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

const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;

int p[300000];
double sum[300000];

int main() {
  int n, K;
  cin >> n >> K;
  rep(i, n) {
    scanf("%d", &p[i]);
    sum[i] = (1 + p[i]) * p[i] / 2 / (double)p[i];
    if (i)
      sum[i] += sum[i - 1];
  }
  double Max = 0;
  rep(i, n) {
    if (i == K - 1)
      Max = max(Max, sum[i]);
    else if (i >= K)
      Max = max(Max, sum[i] - sum[i - K]);
  }
  printf("%.12lf\n", Max);
}
Problem p02780 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define vs vector<string>
#define si set<ll>
#define endl "\n"
#define pb push_back
#define x first
#define y second
// g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main
const int ms = 1e3 + 5, base = 31, mod = 1e9 + 7;
using namespace std;

double P[ms];

void sieve() {
  double sum = 0;
  for (int i = 1; i < ms; i++) {
    sum += i;
    P[i] = sum / i;
  }
}

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

  sieve();
  int n, k;
  cin >> n >> k;

  vi arr;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    arr.pb(a);
  }

  double ans = 0;

  for (int i = 0; i < n - k + 1; i++) {
    double temp = 0;
    for (int j = 0; j < k; j++) {
      // cout << arr[i+j] << " \n"[j==k-1];
      temp += P[arr[i + j]];
    }
    ans = max(ans, temp);
  }

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define vs vector<string>
#define si set<ll>
#define endl "\n"
#define pb push_back
#define x first
#define y second
// g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main
const int ms = 1e3 + 5, base = 31, mod = 1e9 + 7;
using namespace std;

double P[ms];

void sieve() {
  double sum = 0;
  for (int i = 1; i < ms; i++) {
    sum += i;
    P[i] = sum / i;
  }
}

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

  sieve();
  int n, k;
  cin >> n >> k;

  vi arr;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    arr.pb(a);
  }

  double ans = 0;

  double temp = 0;
  for (int j = 0; j < k; j++) {
    temp += P[arr[j]];
  }
  ans = temp;
  for (int i = k; i < n; i++) {
    temp -= P[arr[i - k]];
    temp += P[arr[i]];

    ans = max(ans, temp);
  }

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

  return 0;
}
Problem p02780 (C++)

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

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

  double ans = 0;
  for (int i = 0; i + K <= N; i++) {
    double sum = 0;
    for (int j = i; j < i + K; j++) {
      sum += V[j];
    }
    ans = max(ans, sum);
  }

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


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

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

  double sum = 0;
  rep(i, 0, K - 1) sum += V[i];
  double ans = sum;
  for (int i = 1; i + K <= N; i++) {
    sum -= V[i - 1];
    sum += V[i + K - 1];
    ans = max(ans, sum);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう
#define s(all) s.begin(), s.end()
#define rep(i, n) for (long long i = 0; i < n; i++)
#define ll long long

int main() {
  double ans = 0;
  double x = -1;
  double sum = 0;
  ll n = 0;
  double k = 0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  for (int j = 0; j < (n - k + 1); j++) {
    sum = 0;
    for (int l = 0; l < k; l++) {
      sum += p[j + l];
    }
    cerr << "sum at " << j + 1 << ":" << sum << endl;
    x = max(x, sum);
  }
  ans = (x / 2) + (k / 2);
  cout << fixed << setprecision(15) << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう
#define s(all) s.begin(), s.end()
#define rep(i, n) for (long long i = 0; i < n; i++)
#define ll long long

int main() {
  double ans = 0;
  double x = -1;
  double sum = 0;
  ll n = 0;
  double k = 0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  rep(l, k) sum += p[l];
  cerr << "sum at " << 1 << ":" << sum << endl;
  x = sum;
  for (int j = 0; j < (n - k); j++) {
    sum -= p[j];
    sum += p[j + k];
    cerr << "sum at " << j + 2 << ":" << sum << endl;
    x = max(x, sum);
  }
  ans = (x / 2) + (k / 2);
  cout << fixed << setprecision(15) << ans;
}
Problem p02780 (C++)

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

using namespace std;
#define DBG(x)                                                                 \
  (void)(cout << "L" << __LINE__ << ": " << #x << " = " << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  // 检查有没有特判0,有没有越界限.
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  int n, k;
  vector<double> p(n + 1);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    double x;
    cin >> x;
    double cur = (x + 1) * x * 1.0 / (2 * x);
    // DBG(cur);
    p[i] = cur;
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    p[i] += p[i - 1];
    // DBG(p[i]);
  }
  p[0] = 0;
  for (int i = k; i <= n; i++) {
    ans = max(ans, p[i] - p[i - k]);
    // DBG(ans);
  }
  cout << ans << "\n";
  return 0;
}

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

using namespace std;
#define DBG(x)                                                                 \
  (void)(cout << "L" << __LINE__ << ": " << #x << " = " << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  // 检查有没有特判0,有没有越界限.
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  int n, k;
  vector<double> p(n + 1);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    double x;
    cin >> x;
    double cur = (x + 1) * x * 1.0 / (2 * x);
    // DBG(cur);
    p[i] = cur;
  }
  double ans = 0;
  for (int i = 2; i <= n; i++) {
    p[i] += p[i - 1];
    // DBG(p[i]);
  }
  p[0] = 0;
  for (int i = k; i <= n; i++) {
    ans = max(ans, p[i] - p[i - k]);
    // DBG(ans);
  }
  cout << ans << "\n";
  return 0;
}
Problem p02780 (C++)

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

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

using namespace std;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b)
// { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const long long INF = 1LL << 60;
typedef long long int ll;

#define INF 2000000000

int main() {

  int n, k;
  cin >> n >> k;
  int tindex, num;
  double tmax, tmp;
  double d;
  vector<double> p(n);
  vector<double> a(n + 1, 0);

  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i] = (p[i] + 1) / 2;
    a[i + 1] = a[i] + p[i];
  }

  tmp = 0;

  for (int i = 0; i < k; i++) {

    // if(a[i+k]-a[i] > tmp){
    tmp = std::max(a[i + k] - a[i], tmp);
    //	tmax = tmp;
    //}

    // if(tmax > tmp) d = accumulate(a.begin()+i,a.begin()+i+k,0);
  }

  cout << setprecision(10) << tmp << endl;
}


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

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

using namespace std;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b)
// { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const long long INF = 1LL << 60;
typedef long long int ll;

#define INF 2000000000

int main() {

  int n, k;
  cin >> n >> k;
  int tindex, num;
  double tmax, tmp;
  double d;
  vector<double> p(n);
  vector<double> a(n + 1, 0);

  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i] = (p[i] + 1) / 2;
    a[i + 1] = a[i] + p[i];
  }

  tmp = 0;

  for (int i = 0; i < a.size() - k; i++) {

    // if(a[i+k]-a[i] > tmp){
    tmp = std::max(a[i + k] - a[i], tmp);
    //	tmax = tmp;
    //}

    // if(tmax > tmp) d = accumulate(a.begin()+i,a.begin()+i+k,0);
  }

  cout << setprecision(10) << tmp << endl;
}
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> vec(n);
  for (auto &e : vec) {
    cin >> e;
  }

  vector<int> dp(n);
  int sum = -1;
  int index = 0;
  for (int i = 0; i <= n - k; i++) {
    for (int j = i; j < i + k; j++) {
      dp.at(i) += vec.at(j);
    }
    if (sum < dp.at(i)) {
      sum = dp.at(i);
      index = i;
    }
  }
  double exp = 0;
  for (int i = index; i < index + k; i++) {
    exp += (vec.at(i) + 1) / 2;
  }

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

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

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

  vector<double> vec(n);
  for (auto &e : vec) {
    cin >> e;
  }

  vector<int> dp(n);
  int sum = -1;
  int index = 0;

  for (int i = 0; i < k; i++) {
    dp.at(0) += vec.at(i);
  }
  for (int i = 1; i <= n - k; i++) {
    dp.at(i) = dp.at(i - 1) + vec.at(i + (k - 1)) - vec.at(i - 1);

    if (sum < dp.at(i)) {
      sum = dp.at(i);
      index = i;
    }
  }
  double exp = 0;
  for (int i = index; i < index + k; i++) {
    exp += (vec.at(i) + 1) / 2;
  }

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