Problem p02602 (C++)

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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld", &a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for (ll i = 1; i <= stop; i++)
#define for0(i, stop) for (ll i = 0; i < stop; i++)
#define rep1(i, start) for (ll i = start; i >= 1; i--)
#define rep0(i, start) for (ll i = (start - 1); i >= 0; i--)
#define loop(i, start, stop, inc) for (ll i = start; i <= stop; i += inc)
#define pb(v, a) v.push_back(a)
#define pll pair<ll, ll>
#define mp make_pair
#define pbp(v, a, i) v.push_back(make_pair(a, i))
#define srt(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'

#define _fastio                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

int main() {
  _fastio ll n, k, mx;
  cin >> n >> k;
  ll ar[200005];
  for1(i, n) cin >> ar[i];
  bool fl = true;
  for (ll i = 1; i <= (n - k + 1); i++) {
    ll sm = 0;
    for (ll j = i; j < i + k; j++)
      sm += ar[j];
    if (i == 1)
      mx = sm;
    else {
      if (sm > mx) {
        mx = sm;
        cout << "Yes" << en;
      } else {
        mx = sm;
        cout << "No" << en;
      }
    }
  }
}


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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld", &a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for (ll i = 1; i <= stop; i++)
#define for0(i, stop) for (ll i = 0; i < stop; i++)
#define rep1(i, start) for (ll i = start; i >= 1; i--)
#define rep0(i, start) for (ll i = (start - 1); i >= 0; i--)
#define loop(i, start, stop, inc) for (ll i = start; i <= stop; i += inc)
#define pb(v, a) v.push_back(a)
#define pll pair<ll, ll>
#define mp make_pair
#define pbp(v, a, i) v.push_back(make_pair(a, i))
#define srt(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'

#define _fastio                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

int main() {
  _fastio ll n, k, mx;
  cin >> n >> k;
  ll ar[200005];
  for1(i, n) cin >> ar[i];
  /*ll sm=1;
  for(ll i=1;i<=k;i++)
  {
      sm*=ar[i];
  }
  mx=sm;*/
  for (ll i = 2; i <= (n - k + 1); i++) {
    /*sm=mx;
    sm/=ar[i-1];
    sm*=ar[i+k-1];
    //cout<<sm<<en;*/
    if (ar[i - 1] < ar[i + k - 1]) {
      // mx=sm;
      cout << "Yes" << en;
    } else {
      // mx=sm;
      cout << "No" << en;
    }
  }
}