Problem p02602 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <bitset>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mis map<int, string>
#define msi map<string, int>
#define mll map<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a), greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a, k) lower_bound(all(a), k)
#define ub(a, k) upper_bound(all(a), k)
#define bs(a, k) binary_search(all(a), k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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 I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
  ll N, K;
  cin >> N >> K;
  vl a(N);
  rep(i, N) cin >> a[i];

  ll s = 0;
  rep(i, K) s += a[i];

  rep(i, N - K) {
    ll s2 = s - a[i] + a[i + K];
    if (s2 > s)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    s = s2;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mis map<int, string>
#define msi map<string, int>
#define mll map<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a), greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a, k) lower_bound(all(a), k)
#define ub(a, k) upper_bound(all(a), k)
#define bs(a, k) binary_search(all(a), k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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 I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
  ll N, K;
  cin >> N >> K;
  vl a(N);
  rep(i, N) cin >> a[i];

  // vector<cpp_int> p(N, 1);
  cpp_int p = 1;
  rep(i, K) p *= a[i];

  rep(i, N - K) {
    cpp_int p2 = p / a[i] * a[i + K];
    if (p2 > p)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    p = p2;
  }
}