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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int, int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i, p, q) for (int i = p; i < q; i++)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pi(a) printf("%d\\n", a)
#define psi(a) printf(" %d", a)
#define poi(a) printf("%d", a)
#define sl(a) scanf("%lld", &a)
#define pl(a) printf("%lld\\n", a)
#define Nline() printf("\\n")
#define sstr(str) scanf("%s", str)
#define pstr(str) printf("%s\\n", str)
#define SET(a) memset(a, -1, sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(), (v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ((X) > 0 ? (X) : (-(X)))
#define S(X) ((X) * (X))
const char nl = '\\n';
#define SZ(V) (int)V.size()
#define FORN(i, n) for (i = 0; i < n; i++)
#define FORAB(i, a, b) for (i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C) (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
ll power(ll x, unsigned int y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x % mod;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve() {
  ll n, k;
  cin >> n >> k;
  ll ar[n];
  f(i, 0, n) cin >> ar[i];
  ll pre = 1;
  f(i, 0, k) pre = pre * ar[i];
  ll j = 0;
  ll ans = 1;
  f(i, k, n) {
    ans = ar[i];
    pre = ar[j];
    j++;
    if (ans > pre)
      cout << "Yes"
           << "\\n";
    else
      cout << "No"
           << "\\n";
  }
}
int main() {
  ios;
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int, int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i, p, q) for (int i = p; i < q; i++)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pi(a) printf("%d\\n", a)
#define psi(a) printf(" %d", a)
#define poi(a) printf("%d", a)
#define sl(a) scanf("%lld", &a)
#define pl(a) printf("%lld\\n", a)
#define Nline() printf("\\n")
#define sstr(str) scanf("%s", str)
#define pstr(str) printf("%s\\n", str)
#define SET(a) memset(a, -1, sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(), (v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ((X) > 0 ? (X) : (-(X)))
#define S(X) ((X) * (X))
const char nl = '\\n';
#define SZ(V) (int)V.size()
#define FORN(i, n) for (i = 0; i < n; i++)
#define FORAB(i, a, b) for (i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C) (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
ll power(ll x, unsigned int y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x % mod;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

string multiply(string num1, string num2) {
  int len1 = num1.size();
  int len2 = num2.size();
  if (len1 == 0 || len2 == 0)
    return "0";

  vector<int> result(len1 + len2, 0);

  int i_n1 = 0;
  int i_n2 = 0;

  for (int i = len1 - 1; i >= 0; i--) {
    int carry = 0;
    int n1 = num1[i] - '0';

    i_n2 = 0;

    for (int j = len2 - 1; j >= 0; j--) {
      int n2 = num2[j] - '0';

      int sum = n1 * n2 + result[i_n1 + i_n2] + carry;

      carry = sum / 10;

      result[i_n1 + i_n2] = sum % 10;

      i_n2++;
    }

    if (carry > 0)
      result[i_n1 + i_n2] += carry;

    i_n1++;
  }

  int i = result.size() - 1;
  while (i >= 0 && result[i] == 0)
    i--;

  if (i == -1)
    return "0";

  string s = "";

  while (i >= 0)
    s += std::to_string(result[i--]);

  return s;
}
string divide(string number, int divisor) {

  string ans;

  int idx = 0;
  int temp = number[idx] - '0';
  while (temp < divisor)
    temp = temp * 10 + (number[++idx] - '0');

  while (number.size() > idx) {
    ans += (temp / divisor) + '0';
    temp = (temp % divisor) * 10 + number[++idx] - '0';
  }

  if (ans.length() == 0)
    return "0";

  return ans;
}
bool comp(string a, string b) {
  if (a.length() > b.length())
    return 1;
  else if (a.length() < b.length())
    return 0;
  return a > b;
}

void solve() {
  ll n, k;
  cin >> n >> k;
  int ar[n];
  f(i, 0, n) cin >> ar[i];
  //	unsigned ll pre=1;
  string pre = "1";
  f(i, 0, k) {
    string a = to_string(ar[i]);
    pre = multiply(pre, a);
  }

  ll j = 0;
  // unsigned ll ans=1;
  string ans;
  f(i, k, n) {
    string p = pre;
    ans = multiply(divide(pre, ar[j]), to_string(ar[i]));
    j++;

    // cout<<pre <<" "<<ans<<"\\n";

    if (comp(ans, p))
      cout << "Yes"
           << "\\n";
    else
      cout << "No"
           << "\\n";

    pre = ans;
  }
}
int main() {
  ios;
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}