Problem:
Lottery Box
A lottery is being held in a corner of the venue of the Aizu festival. Several types of balls are inside the lottery box and each type has its unique integer printed on the surfaces of the balls. An integer
T
is printed on the lottery box.
In the lottery, you first declare two integers
A
and
B
, and draw up to
M
balls from the box. Let the sum of the integers printed on the balls be
S
. You can get a wonderful gift if the following two criteria are met:
S
divided by
T
gives a remainder greater than or equal to
A
, and
S
divided by
T
gives a quotient (fractional portion dropped) greater than or equal to
B
.
Write a program to determine if you have any chance of getting the gift given the following information: the number of ball types, ball-type specific integers, the maximum number of balls to be drawn from the box, the integer printed on the lottery box, and two integers declared before drawing. Assume that each ball type has sufficient (≥M) population in the box. Note also that there may be a chance of getting the gift even without drawing any ball.
Input
The input is given in the following format.
N
M
T
a_1
a_2
:
a_N
Q
A_1
B_1
A_2
B_2
:
A_Q
B_Q
The first line provides the number of ball types
N
(1≤
N
≤10
5
), the maximum number of balls you can draw from the box
M
(1≤
M
≤10
5
), and the integer printed on the box
T
(1≤
T
≤1000). Each of the subsequent
N
lines provides an integer
a_i
(1≤
a_i
≤10
9
) printed on the
i
-th ball type. The next line following these provides the number of declarations
Q
(1≤
Q
≤10
5
). Each of the
Q
lines following this provides a pair of integers
A_i
(0 ≤
A_i
<
T
),
B_i
(0 ≤
B_i
≤ 10
9
) that constitute the
i
-th declaration.
Output
Output a line for each pair of declaration
A
and
B
that contains "
yes
" if there is a chance of getting the gift or "
no
" otherwise.
Sample Input 1
3 2 7
8
3
6
5
2 2
3 2
4 1
6 1
6 0
Sample Output 1
yes
no
yes
no
yes

Submitted solutions:

code_snippet: // AOJ #376
// Lottery Box 2025.2.8

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

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(bool yes) { // 整数の表示（出力）
    if (yes) pc('y'), pc('e'), pc('s');
    else pc('n'), pc('o');
    pc('\n');
}


const ll NEG_INF = -1000000000000000000LL;
 
int T_val;
 
 
vector<ll> convFunc(const vector<ll>& A, const vector<ll>& B) {
    int T = T_val;
    vector<ll> C(T, NEG_INF);
    for (int x = 0; x < T; x++) {
        ll best = NEG_INF;
        for (int k = 0; k <= x; k++) {
            ll aVal = A[k], bVal = B[x - k];
            if(aVal==NEG_INF || bVal==NEG_INF) continue;
            ll cand = aVal + bVal;
            if(cand > best) best = cand;
        }
        for (int k = x+1; k < T; k++) {
            ll aVal = A[k], bVal = B[x + T - k];
            if(aVal==NEG_INF || bVal==NEG_INF) continue;
            ll cand = aVal + bVal + 1;
            if(cand > best) best = cand;
        }
        C[x] = best;
    }
    return C;
}
 
int main() {
    int N = Cin();
    ll  M = Cin();
    int T = Cin();
    T_val = T;
    vector<ll> bestW(T, NEG_INF);
    for (int i = 0; i < N; i++){
        int a = Cin();
        int r = a % T;
        ll  q = a / T;
        bestW[r] = max(bestW[r], q);
    }
 
    vector<ll> baseFunc(T, NEG_INF);
    for (int x = 0; x < T; x++){
        baseFunc[x] = bestW[x];
    }
 
    int maxPow = 0;
    while ((1LL << (maxPow+1)) <= M) maxPow++;
 
    vector< vector<ll> > powFunc(maxPow+1, vector<ll>(T, NEG_INF));
    powFunc[0] = baseFunc;
    for (int i = 1; i <= maxPow; i++){
        powFunc[i] = convFunc(powFunc[i-1], powFunc[i-1]);
    }
 
    vector<ll> dp(T, NEG_INF);
    dp[0] = 0;
    for (int i = 0; i <= maxPow; i++){
        if (M & (1LL << i)) dp = convFunc(dp, powFunc[i]);
    }
 
    vector<ll> tot(T, NEG_INF);
    for (int x = 0; x < T; x++){
        if(dp[x]==NEG_INF) tot[x] = NEG_INF;
        else tot[x] = (ll)T * dp[x] + x;
    }
 
    int Q = Cin();
    for (int i = 0; i < Q; i++){
        int A = Cin(), B = Cin();
        ll threshold = (ll)T * B + A;
        ll best = NEG_INF;
        for (int r = A; r < T; r++){
            best = max(best, tot[r]);
        }
        Cout(best >= threshold);
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3552
final_rank: 5

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	// step #1. input
	int N, M, T;
	cin >> N >> M >> T;
	vector<long long> X(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	int Q;
	cin >> Q;
	vector<int> A(Q);
	vector<long long> B(Q);
	for (int i = 0; i < Q; i++) {
		cin >> A[i] >> B[i];
	}

	// step #2. find best
	const long long INF = (3LL << 60);
	vector<long long> Z(T, -INF);
	for (int i = 0; i < N; i++) {
		Z[X[i] % T] = max(Z[X[i] % T], X[i] / T);
	}

	// step #3. dynamic programming
	auto merge = [&](const vector<long long>& v1, const vector<long long>& v2) -> vector<long long> {
		vector<long long> v(T, -INF);
		for (int i = 0; i < T; i++) {
			for (int j = 0; j < T; j++) {
				if (v1[i] != -INF && v2[j] != -INF) {
					if (i + j < T) {
						v[i + j] = max(v[i + j], v1[i] + v2[j]);
					}
					else {
						v[i + j - T] = max(v[i + j - T], v1[i] + v2[j] + 1);
					}
				}
			}
		}
		return v;
	};
	vector<long long> cur = Z;
	vector<long long> dp(T, -INF);
	dp[0] = 0;
	while (M >= 1) {
		if (M % 2 == 1) {
			dp = merge(dp, cur);
		}
		cur = merge(cur, cur);
		M /= 2;
	}

	// step #4. reform answer
	vector<long long> answer = dp;
	for (int i = T - 2; i >= 0; i--) {
		answer[i] = max(answer[i], answer[i + 1]);
	}
	
	// step #5. answer queries
	for (int i = 0; i < Q; i++) {
		cout << (answer[A[i]] >= B[i] ? "yes\n" : "no\n");
	}

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5064
final_rank: 18

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0376.cc: Lottery Box
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_T = 1000;
const int BN = 17;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll bs[BN][MAX_T], mbs[MAX_T], tmp[MAX_T], mxds[MAX_T + 1];

/* subroutines */

void setmax(ll &a, ll b) { if (a < b) a = b; }

void mulv(int t, const ll a[], const ll b[], ll c[]) {
  fill(c, c + t, -1);
  for (int i = 0; i < t; i++)
    if (a[i] >= 0)
      for (int j = 0; j < t; j++)
	if (b[j] >= 0) {
	  ll q = a[i] + b[j] + (i + j) / t;
	  int r = (i + j) % t;
	  setmax(c[r], q);
	}
}

/* main */

int main() {
  int n, m, t;
  scanf("%d%d%d", &n, &m, &t);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  fill(bs[0], bs[0] + t, -1);
  for (int i = 0; i < n; i++) {
    int q = as[i] / t, r = as[i] % t;
    bs[0][r] = max(bs[0][r], (ll)q);
  }

  for (int i = 0; i < BN - 1; i++)
    mulv(t, bs[i], bs[i], bs[i + 1]);

  fill(mbs, mbs + t, -1);
  mbs[0] = 0;

  for (int i = 0, bi = 1; i < BN; i++, bi <<= 1)
    if (m & bi) {
      mulv(t, mbs, bs[i], tmp);
      copy(tmp, tmp + t, mbs);
    }

  mxds[t] = -1;
  for (int i = t - 1; i >= 0; i--)
    mxds[i] = max(mxds[i + 1], mbs[i]);
  //for (int i = 0; i < t; i++) printf("%lld ", mxds[i]); putchar('\n');

  int qn;
  scanf("%d", &qn);

  while (qn--) {
    int a, b;
    scanf("%d%d", &a, &b);

    if (mxds[a] >= b) puts("yes");
    else puts("no");
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3352
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int N,M,T;
long A[17][1000];
long dp[1000],tmp[1000];
main()
{
	cin>>N>>M>>T;
	for(int i=1;i<T;i++)A[0][i]=-1e18;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		A[0][a%T]=max(A[0][a%T],(long)a/T);
	}
	for(int i=1;i<17;i++)
	{
		for(int j=1;j<T;j++)A[i][j]=-1e18;
		for(int j=0;j<T;j++)for(int k=0;k<T;k++)
		{
			A[i][(j+k)%T]=max(A[i][(j+k)%T],A[i-1][j]+A[i-1][k]+(j+k)/T);
		}
	}
	for(int j=1;j<T;j++)dp[j]=-1e18;
	for(int i=0;i<17;i++)if(M>>i&1)
	{
		for(int j=0;j<T;j++)
		{
			tmp[j]=dp[j];
			dp[j]=-1e18;
		}
		dp[0]=0;
		for(int j=0;j<T;j++)for(int k=0;k<T;k++)
		{
			dp[(j+k)%T]=max(dp[(j+k)%T],A[i][j]+tmp[k]+(j+k)/T);
		}
	}
	for(int j=T-1;j--;)dp[j]=max(dp[j],dp[j+1]);
	int Q;cin>>Q;
	for(;Q--;)
	{
		int A,B;cin>>A>>B;
		cout<<(dp[A]>=B?"yes":"no")<<endl;
	}
}
accuracy: 1
time_ms: 220
memory_kb: 3264
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define eb emplace_back
using namespace std;
const char newl='\n';
template<class T>
using V=vector<T>;
using ll=long long;
const ll inf=1LL<<60;
int main(){
    ll n,m,t;cin>>n>>m>>t;
    V<ll> a(n),b(t,-inf);
    b[0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[a[i]%t]=max(b[a[i]%t],a[i]);
    }
    V<V<ll>> dp(30,V<ll>(t,-inf));
    for(int i=0;i<t;i++){
        dp[0][i]=b[i];
    }
    for(int i=0;i+1<30;i++){
        for(int j=0;j<t;j++){
            for(int k=0;k<t;k++){
                if(dp[i][j]==-inf||dp[i][k]==-inf)continue;
                dp[i+1][(j+k)%t]=max(dp[i+1][(j+k)%t],dp[i][j]+dp[i][k]);
            }
        }
    }
    V<V<ll>> ma(2,V<ll>(t,-inf));
    int pre=0,cur=1;
    ma[pre][0]=0;
    for(int i=29;i>=0;i--){
        if((m>>i)&1){
            for(int j=0;j<t;j++)ma[cur][j]=-inf;
            for(int j=0;j<t;j++){
                if(ma[pre][j]==-inf)continue;
                for(int k=0;k<t;k++){
                    if(dp[i][k]==-inf)continue;
                    ma[cur][(j+k)%t]=max(ma[cur][(j+k)%t],ma[pre][j]+dp[i][k]);
                }
            }
            swap(pre,cur);
        }
    }
    for(int i=t-2;i>=0;i--){
        ma[pre][i]=max(ma[pre][i+1],ma[pre][i]);
    //    cout<<i<<" "<<ma[pre][i]<<newl;
    }
    int q;cin>>q;
    while(q--){
        int A,B;cin>>A>>B;
        if(ma[pre][A]>=B*t){
            cout<<"yes"<<newl;
        }else{
            cout<<"no"<<newl;
        }
    }
}
accuracy: 1
time_ms: 400
memory_kb: 3844
final_rank: 17

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define vvel V<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define sor(s) sort(s.begin(),s.end())
vel mul(vel a, vel b) {
	int t = a.size();
	vel ans(t, -1);
	rep(i, t) {
		rep(j, t) {
			if (a[i] >= 0 && b[j] >= 0) {
				mmax(ans[(i + j) % t], a[i] + b[j] + ((i + j) / t));
			}
		}
	}
	return ans;
}
vel rui(int a, vel & nex) {
	if (a == 1) { return nex; }
	vel ans = rui(a / 2, nex);
	ans = mul(ans, ans);
	if (a % 2 == 1) {
		ans = mul(ans, nex);
	}
	return ans;
}
signed main() {
	int n, m, t; cin >> n >> m >> t;
	vel nex(t, -1); nex[0] = 0;
	rep(i, n) {
		int a;
		cin >> a;
		mmax(nex[a % t], a / t);
	}
	vel ans = rui(m, nex);
	for (int i = t - 2; i >= 0; i--) {
		mmax(ans[i], ans[i + 1]);
	}
	int q; cin >> q;
	rep(i, q) {
		int a, b; cin >> a >> b;
		if (ans[a] >= b) { cout << "yes" << endl; }
		else { cout << "no" << endl; }
	}
	return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 3196
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)

int main(){
    int N, M, T;
    cin >> N >> M >> T;
    vector<lint> max_by_mod(T, -1);
    max_by_mod[0] = 0;
    rep(i, N){
        lint a;
        cin >> a;
        max_by_mod[a % T] = max(max_by_mod[a % T], a);
    }
    
    lint doubling[20][T];
    rep(i, T){
        doubling[0][i] = max_by_mod[i];
    }
    rep2(i, 1, 20){
        rep(j, T){
            doubling[i][j] = -1;
            rep(k, T){
                if(doubling[i - 1][k] == -1 || doubling[i - 1][(j - k + T) % T] == -1){
                    continue;
                }
                doubling[i][j] = max(doubling[i][j], doubling[i - 1][k] + doubling[i - 1][(j - k + T) % T]);
            }
        }
    }
    
    lint doubling_M[21][T]; // あとでTにする
    rep(i, T) doubling_M[20][i] = -1;
    doubling_M[20][0] = 0;
    repr(i, 20){
        rep(j, T){
            if(~(M >> i) & 1){
                doubling_M[i][j] = doubling_M[i + 1][j];
                continue;
            }
            if(i == 0 && j == 3){
                
            }
            doubling_M[i][j] = -1;
            rep(k, T){
                if(doubling_M[i + 1][k] == -1 || doubling[i][(j - k + T) % T] == -1){
                    continue;
                }
                doubling_M[i][j] = max(doubling_M[i][j], doubling_M[i + 1][k] + doubling[i][(j - k + T) % T]);
            }
        }
    }
    lint cum_max[T + 1];
    cum_max[T] = -1;
    repr(i, T){
        cum_max[i] = max(cum_max[i + 1], doubling_M[0][i]);
    }
    
    int Q;
    cin >> Q;
    rep(i, Q){
        lint A, B;
        cin >> A >> B;
        if(cum_max[A] >= B * T + A){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 1
time_ms: 190
memory_kb: 3316
final_rank: 11

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m, t;
    cin >> n >> m >> t;
    vector<ll> v(t, -INF<ll>);
    v[0] = 0;
    for (int i = 0; i < n; ++i) {
        ll x; scanf("%lld", &x);
        chmax(v[x%t], x/t);
    }
    vector<ll> a(t, -INF<ll>);
    a[0] = 0;
    auto merge = [&](vector<ll> &a, vector<ll> &b){
        vector<ll> ans(t, -INF<ll>);
        for (int i = 0; i < t; ++i) {
            for (int j = 0; j < t; ++j) {
                if(i+j >= t) chmax(ans[i+j-t], a[i]+b[j]+1);
                else chmax(ans[i+j], a[i]+b[j]);
            }
        }
        return ans;
    };
    while(m){
        if(m&1) a = merge(a, v);
        v = merge(v, v);
        m >>= 1;
    }
    for (int i = t-1; i > 0; --i) {
        chmax(a[i-1], a[i]);
    }
    int q;
    cin >> q;
    while(q--){
        int x, y; scanf("%d %d", &x, &y);
        puts(a[x] >= y ? "yes" : "no");
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3492
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	int n, m, t; std::cin >> n >> m >> t;
	std::vector<int> balls(n); for (auto& a : balls) std::cin >> a;
	std::vector<std::vector<long long int>> max_b{ std::vector<long long int>(t, -1) };
	for (const auto a : balls) {
		max_b[0][a % t] = std::max(max_b[0][a % t], (long long int)a / t);
	}
	for (auto _c = 1; (1 << _c) <= m; ++_c) {
		std::vector<long long int> last(t, -1);
		for (auto i = 0; i < t; ++i) if (max_b.back()[i] != -1) {
			for (auto j = 0; j <= i; ++j) if (max_b.back()[j] != -1) {
				last[(i + j) % t] = std::max(last[(i + j) % t], max_b.back()[i] + max_b.back()[j] + (i + j) / t);
			}
		}
		max_b.push_back(std::move(last));
	}
	auto result = max_b.back();
	for (auto i = 0; i + 1 < max_b.size(); ++i) if ((m & (1 << i)) != 0) {
		auto last = result;
		for (auto j = 0; j < t; ++j) if (max_b[i][j] != -1) {
			for (auto k = 0; k < t; ++k) if (last[k] != -1) {
				result[(j + k) % t] = std::max(result[(j + k) % t], max_b[i][j] + last[k] + (j + k) / t);
			}
		}
	}
	for (auto i = 2; i <= result.size(); ++i) {
		result[result.size() - i] = std::max(result[result.size() - i], result[result.size() - i + 1]);
	}
	int q; std::cin >> q;
	for (auto i = 0; i < q; ++i) {
		int a, b; std::cin >> a >> b;
		std::cout << (result[a] >= b ? "yes\n" : "no\n");
	}
}
accuracy: 1
time_ms: 170
memory_kb: 3316
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr ll INF = INT_MAX;

void chmax(ll &a, ll b){
    a = max(a, b);
}

int main() {
    int N, M, T;
    cin >> N >> M >> T;
    vector<vector<ll> > dp(21,vector<ll>(T,-INF/2));  // dp[i][j] 2^i個以下のボールを使って余りをjにするときの商の最大
    dp[0][0] = 0;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        chmax(dp[0][a%T], a/T);
    }
    // ダブリング
    for(int i=0;i<20;i++){
        for(int j=0;j<T;j++){
            for(int k=j;k<T;k++){
                int l = (j+k)%T, c = (j+k)/T;
                chmax(dp[i+1][l], dp[i][l]);
                if(dp[i][j] >= 0 && dp[i][j] >= 0){
                    chmax(dp[i+1][l], dp[i][j]+dp[i][k] + c);
                }
            }
        }
    }
    // dpを元にM個以下のときの最大値を計算
    vector<vector<ll> > ans(2,vector<ll>(T,-INF/2));
    ans[0][0] = 0;
    for(int m=M,i=0;m>0;m>>=1,i++){
        if(m&1){
            for(int j=0;j<T;j++){
                for(int k=0;k<T;k++){
                    int l = (j+k)%T, c = (j+k)/T;
                    chmax(ans[1][l], ans[0][l]);
                    if(ans[0][j] >= 0 && dp[i][k] >= 0){
                        chmax(ans[1][l], ans[0][j]+dp[i][k]+c);
                    }
                }
            }
            for(int j=0;j<T;j++){
                ans[0][j] = ans[1][j];
            }
        }
    }
    // 累積max
    for(int i=T-2;i>=0;i--){
        chmax(ans[0][i], ans[0][i+1]);
    }
    int Q;
    cin >> Q;
    for(;Q>0;Q--){
        ll a, b;
        cin >> a >> b;
        if(ans[0][a] >= b){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 3248
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr ll INF = INT_MAX;

void chmax(ll &a, ll b){
    a = max(a, b);
}

template <typename Monoid>
struct SegmentTree{
private:
    using F = function<Monoid(Monoid, Monoid)>;
    int N;
    vector<Monoid> node;
    F f;
    Monoid e;  // identity element

public:
    SegmentTree(){}
    SegmentTree(F f, Monoid e):f(f), e(e){}
    void init(int sz){
        N = 1;
        while(N < sz) N <<= 1;
        node.assign(2*N-1, e);
    }
    void build(vector<Monoid>& v){
        int sz = int(v.size());
        init(sz);
        for(int i=0; i<sz; i++){
            node[i+N-1] = v[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }
    void update(int k, Monoid x){
        k += N-1;
        node[k] = x;
        while(k > 0){
            k = (k-1)/2;
            node[k] = f(node[2*k+1], node[2*k+2]);
        }
    }
    // [a,b)
    Monoid query(int a, int b){return query(a, b, 0, 0, N);}
    Monoid query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a) return e;
        if(a <= l && r <= b) return node[k];
        Monoid vl, vr;
        vl = query(a, b, 2*k+1, l, (l+r)/2);
        vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

auto f = [=](ll a, ll b){return max(a, b);};
SegmentTree<ll> seg(f,-INF);
 

int main() {
    int N, M, T;
    cin >> N >> M >> T;
    vector<vector<ll> > dp(21,vector<ll>(T,-INF/2));  // dp[i][j] 2^i個以下のボールを使って余りをjにするときの商の最大
    dp[0][0] = 0;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        chmax(dp[0][a%T], a/T);
    }
    for(int i=0;i<20;i++){
        for(int j=0;j<T;j++){
            for(int k=j;k<T;k++){
                int l = (j+k)%T, c = (j+k)/T;
                chmax(dp[i+1][l], dp[i][l]);
                if(dp[i][j] >= 0 && dp[i][j] >= 0){
                    chmax(dp[i+1][l], dp[i][j]+dp[i][k] + c);
                }
            }
        }
    }
    vector<vector<ll> > ans(2,vector<ll>(T,-INF/2));
    ans[0][0] = 0;
    for(int m=M,i=0;m>0;m>>=1,i++){
        if(m&1){
            for(int j=0;j<T;j++){
                for(int k=0;k<T;k++){
                    int l = (j+k)%T, c = (j+k)/T;
                    chmax(ans[1][l], ans[0][l]);
                    if(ans[0][j] >= 0 && dp[i][k] >= 0){
                        chmax(ans[1][l], ans[0][j]+dp[i][k]+c);
                    }
                }
            }
            for(int j=0;j<T;j++){
                ans[0][j] = ans[1][j];
            }
        }
    }
    seg.build(ans[0]);
    int Q;
    cin >> Q;
    for(;Q>0;Q--){
        ll a, b;
        cin >> a >> b;
        if(seg.query(a,T) >= b){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 3280
final_rank: 10

code_snippet: #include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, m, t;
    cin >> n >> m >> t;

    lint dp1[20][1000];
    fill(dp1[0], dp1[20], -1LL);

    lint dp2[1000];
    fill(dp2, dp2 + t, -1LL);

    rep(i, n){
        lint a;
        cin >> a;
        chmax(dp1[0][a % t], a);
    }

    rep(i, 19){
        rep(j, t){
            chmax(dp1[i + 1][j], dp1[i][j]);
            rep(k, t){
                if(dp1[i][j] >= 0LL && dp1[i][k] >= 0LL){
                    chmax(dp1[i + 1][(j + k) % t], dp1[i][j] + dp1[i][k]);
                }
            }
        }
    }

    rep(i, 20){
        if(!(m >> i & 1)){
            continue;
        }
        lint dp3[1000];
        rep(j, t){
            dp3[j] = dp2[j];
        }
        rep(j, t){
            chmax(dp3[j], dp1[i][j]);
            rep(k, t){
                if(dp1[i][j] >= 0LL && dp2[k] >= 0LL){
                    chmax(dp3[(j + k) % t], dp1[i][j] + dp2[k]);
                }
            }
        }
        rep(j, t){
            dp2[j] = dp3[j];
        }
    }

    rrep(j, t - 1){
        chmax(dp2[j], dp2[j + 1]);
    }

    int q;
    cin >> q;

    while(q--){
        int a, b;
        cin >> a >> b;
        if(dp2[a] >= 0LL && dp2[a] / t >= b){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    cout << flush;

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3284
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int a[2000];
ll dp[18][2000];
ll DP[2][2000];
ll sum[2000];

int main(){
    int n,m,T;cin>>n>>m>>T;
    memset(a,-1,sizeof(a));
    a[0]=0;
    rep(i,n){
        int b;scanf("%d",&b);
        a[b%T]=max(a[b%T],b);
    }
    memset(dp,-1,sizeof(dp));
    rep(i,T){
        dp[0][i]=a[i];
    }
    rep(i,18){
        rep(j,T){
            if(dp[i][j]==-1)continue;   
            rep(k,T){
                if(dp[i][k]==-1)continue;
                dp[i+1][(j+k)%T]=max(dp[i+1][(j+k)%T],dp[i][j]+dp[i][k]);
            }
        }
    }
    memset(DP,-1,sizeof(DP));
    DP[0][0]=0;
    rep(i,18){
        rep(j,T)DP[(i+1)%2][j]=max(DP[(i+1)%2][j],DP[i%2][j]);
        if(!(m>>i&1))continue;
        rep(j,T){
            rep(k,T){
                if(DP[i%2][j]==-1||dp[i][k]==-1)continue;
                DP[(i+1)%2][(j+k)%T]=max(DP[(i+1)%2][(j+k)%T],DP[i%2][j]+dp[i][k]);
            }
		}
	}
	sum[T]=-1;
    for(int i=T-1;i>=0;i--){
        sum[i]=max(DP[0][i],sum[i+1]);
    }
    int q;cin>>q;
    rep(i,q){
        int a,b;scanf("%d%d",&a,&b);
        if(sum[a]>=T*(ll)b){
            puts("yes");
        }
        else puts("no");
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3456
final_rank: 6

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int num_lp(int a, vel &nex) {
	unordered_set<int> se;
	int ans = 0;
	while (true) {
		if (se.find(a) != se.end()) {
			break;
		}
		se.insert(a);
		a = nex[a];
		ans++;
	}
	return ans;
}
int find_cr(int a, vel &nex) {
	unordered_set<int> se;
	while (true) {
		if (se.find(a) != se.end()) {break;}
		se.insert(a);
		a = nex[a];
	}
	return num_lp(a, nex);
}
int inf = 2000000000;
vvel dp;
int solve(vvel &sum, int i, int j, bool is_f) {
	int h = sum.size(); h--;
	int w = sum[0].size();
	if (i == h || j == w) { return 0; }
	if (dp[i][j] == inf) {
		int ans1 = solve(sum, i + 1, j, !is_f);
		int ans2 = solve(sum, i, j + 1, !is_f);
		ans2 += sum[i][j];
		if (is_f) {
			dp[i][j] = min(ans1, ans2);
		}
		else {
			dp[i][j] = max(ans1, ans2);
		}
	}
	return dp[i][j];
}
int rui10(int a) {
	if (a == 0) { return 1; }
	return 10 * rui10(a - 1);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
vel mul(vel &a, vel &b) {
	int n = a.size();
	vel c(n,-1);
	rep(i, n) {
		rep(j, n) {
			if (a[i] >= 0 && b[j] >= 0) {
				mmax(c[(i + j) % n], a[i] + b[j]);
			}
		}
	}
	return c;
}
vel rui(vel &a, int n) {
	if (n == 1) { return a; }
	vel b = rui(a, n / 2);
	b = mul(b, b);
	if (n % 2 == 1) {
		b = mul(b, a);
	}
	return b;
}
signed main(){
	int n, m, t; cin >> n >> m >> t;
	vel a(t, -1); a[0] = 0;
	rep(i, n) {
		int x; cin >> x;
		mmax(a[x%t], x);
	}
	vel ans = rui(a, m);
	for (int i = t - 2; i >= 0; i--) {
		mmax(ans[i], ans[i + 1]);
	}
	int q; cin >> q;
	rep(i, q) {
		int x, y; cin >> x >> y;
		if (ans[x] >= y * t + x) { cout << "yes" << endl; }
		else { cout << "no" << endl; }
	}
	return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 4184
final_rank: 16

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define vel vector<int>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int num_lp(int a, vel &nex) {
	unordered_set<int> se;
	int ans = 0;
	while (true) {
		if (se.find(a) != se.end()) {
			break;
		}
		se.insert(a);
		a = nex[a];
		ans++;
	}
	return ans;
}
int find_cr(int a, vel &nex) {
	unordered_set<int> se;
	while (true) {
		if (se.find(a) != se.end()) {break;}
		se.insert(a);
		a = nex[a];
	}
	return num_lp(a, nex);
}
int inf = 2000000000;
vvel dp;
int solve(vvel &sum, int i, int j, bool is_f) {
	int h = sum.size(); h--;
	int w = sum[0].size();
	if (i == h || j == w) { return 0; }
	if (dp[i][j] == inf) {
		int ans1 = solve(sum, i + 1, j, !is_f);
		int ans2 = solve(sum, i, j + 1, !is_f);
		ans2 += sum[i][j];
		if (is_f) {
			dp[i][j] = min(ans1, ans2);
		}
		else {
			dp[i][j] = max(ans1, ans2);
		}
	}
	return dp[i][j];
}
int rui10(int a) {
	if (a == 0) { return 1; }
	return 10 * rui10(a - 1);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
vel mul(vel &a, vel &b) {
	int n = a.size();
	vel c(n,-1);
	rep(i, n) {
		rep(j, n) {
			if (a[i] >= 0 && b[j] >= 0) {
				mmax(c[(i + j) % n], a[i] + b[j]);
			}
		}
	}
	return c;
}
vel rui(vel &a, int n) {
	if (n == 1) { return a; }
	vel b = rui(a, n / 2);
	b = mul (b, b);
	if (n % 2 == 1) {
		b = mul(b, a);
	}
	return b;
}
signed main(){
	int n, m, t; cin >> n >> m >> t;
	vel a(t, -1); a[0] = 0;
	rep(i, n) {
		int x; cin >> x;
		mmax(a[x%t], x);
	}
	vel ans = rui(a, m);
	for (int i = t - 2; i >= 0; i--) {
		mmax(ans[i], ans[i + 1]);
	}
	int q; cin >> q;
	rep(i, q) {
		int x, y; cin >> x >> y;
		if (ans[x] >= y * t + x) { cout << "yes" << endl; }
		else { cout << "no" << endl; }
	}
	return 0;
}
accuracy: 0.375
time_ms: 130
memory_kb: 3196
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define DBG(x) ;//cerr<<#x<<" = "<<x<<endl
using LL = long long;

LL N,M,T;

LL INF = 123456789012345678;

struct node{
	vector<LL>vec;
	node(){
		vec.resize(T);
	}
	node operator + (const node&o){
		node x = *this;
		for(int i = 0;i < T;++i){
			for(int j = 0;j < T;++j){
				x.vec[(i+j)%T] = max(x.vec[(i+j)%T],
				vec[i]+o.vec[j]);
			}
		}
		return x;
	}
};

node m_pow(const node&e,LL x){
	if(x == 1)return e;
	node half = m_pow(e,x/2);
	half = half + half;
	if(x % 2)half = half + e;
	return half;
}

int main(){
	cin>>N>>M>>T;
	node e;
	fill(e.vec.begin(),e.vec.end(),-INF);
	e.vec[0] = 0;
	for(int i=0;i<N;++i){
		LL a;cin>>a;
		e.vec[a%T]=max(a,e.vec[a%T]);
	}
	auto res = m_pow(e,M);
	vector<LL>ans(T+1,-INF);
	for(int i=0;i<T;++i){
		ans[i]=res.vec[i];
	}
	for(int i=T-1;i>=0;--i){
		ans[i]=max(ans[i],ans[i+1]);
	}
	for(int i=0;i<T;++i){
		ans[i]/=T;
		//ans[i]++;
		DBG(ans[i]);
	}
	int Q;
	cin>>Q;
	for(int q=0;q<Q;++q){
		LL A,B;
		cin>>A>>B;
		if(ans[A]>=B){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 3180
final_rank: 14

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

#define MAX 100002

int n;
int m;

int t;

map<long long int,long long int> mp;

int q;

#define MAX_T 1002

long long int dp[MAX_T];
long long int f[MAX_T];

long long int tmp[MAX_T];

int main(){
	cin>>n>>m>>t;
	mp[0]=0;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		if(mp.count(a%t)==0){
			mp[a%t]=0;
		}
		mp[a%t]=max(mp[a%t],(long long int)a);
	}
	for(int i=0;i<t;i++)dp[i]=LLONG_MIN;
	dp[0]=0;
	for(int i=0;i<t;i++){
		f[i]=LLONG_MIN;
		if(mp.count(i)){
			f[i]=mp[i];
		}
	}
	while(m){
		if(m&1){
			for(int j=0;j<t;j++)tmp[j]=dp[j];
			for(int j=0;j<t;j++){
			if(dp[j]==LLONG_MIN)continue;
				for(int k=0;k<t;k++){
				if(f[k]==LLONG_MIN)continue;
					tmp[(j+k)%t]=max(tmp[(j+k)%t],dp[j]+f[k]);
				}
			}
			for(int j=0;j<t;j++)dp[j]=tmp[j];
		}
		for(int j=0;j<t;j++)tmp[j]=f[j];
			for(int j=0;j<t;j++){
			if(f[j]==LLONG_MIN)continue;
				for(int k=0;k<t;k++){
				if(f[k]==LLONG_MIN)continue;
					tmp[(j+k)%t]=max(tmp[(j+k)%t],f[j]+f[k]);
				}
			}
			for(int j=0;j<t;j++)f[j]=tmp[j];
		m>>=1;
	}
	for(int j=t-2;j>=0;j--){
		dp[j]=max(dp[j],dp[j+1]);
	}
	cin>>q;
	while(q--){
		int a,b;
		scanf("%d%d",&a,&b);
		if(dp[a]>=(long long int)(b)*(long long int)(t)){
			puts("yes");
		}
		else{
			puts("no");
		}
	}
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3248
final_rank: 1

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 100000


int main(void){
long long n,m;
long long t;
long long s,tt;
long long a[2000][30];
long long b[2000];
long long b2[2000];
f(i,2000){
f(j,30)a[i][j]=-1;
b[i]=-1;
b2[i]=-1;
}
a[0][0]=0;
long long x,y,z;
scanf("%lld %lld %lld",&n,&m,&t);
f(i,n){
scanf("%lld",&x);
if(a[(x%t)][0]<x)a[(x%t)][0]=x;
}
f(ii,29){
f(i,t)a[i][ii+1]=a[i][ii];
f(i,t){
f(j,t){
if(a[i][ii]!=-1&&a[j][ii]!=-1){
s=(i+j)%t;
if(a[s][ii+1]<a[i][ii]+a[j][ii])a[s][ii+1]=a[i][ii]+a[j][ii];
}
}
}
}
tt=0;
f(ii,30){
if(m%2==1){
if(tt==0){
f(i,t)b[i]=a[i][ii];
}
else{
f(i,t)b2[i]=b[i];
f(i,t){
f(j,t){
if(b[i]!=-1&&a[j][ii]!=-1){
s=(i+j)%t;
if(b2[s]<b[i]+a[j][ii])b2[s]=b[i]+a[j][ii];
}
}
}
f(i,t)b[i]=b2[i];
}
tt++;
}
m=m/2;
}
f(i,t)if(b[i]!=-1)b[i]=b[i]/t;
f(i,t-1)b[t-i-2]=max(b[t-i-2],b[t-i-1]);
long long q;
long long aa;
long long bb;
scanf("%lld",&q);
f(i,q){
scanf("%lld %lld",&aa,&bb);
if(bb<=b[aa])printf("yes\n");
else printf("no\n");

}

return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 3176
final_rank: 13

code_snippet: #include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	i64 n, m, t; cin >> n >> m >> t; std::vector<i64> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(begin(a), end(a));
	
	std::vector<std::vector<i64>> dp(20, std::vector<i64>(t, -(1LL << 60))); dp[0][0] = 0;
	for(int i = 0; i < n; i++) {
		dp[0][a[i] % t] = std::max(dp[0][a[i] % t], a[i]);
	}
	
	for(int k = 0; m >> (k + 1); k++) {
		for(int i = 0; i < t; i++) {
			for(int j = 0; j < t; j++) {
				dp[k + 1][(i + j) % t] = std::max(dp[k + 1][(i + j) % t], dp[k][i] + dp[k][j]);
			}
		}
	}
	
	int c = 0;
	std::vector<std::vector<i64>> dp2(2, std::vector<i64>(t, -(1LL << 60))); dp2[0][0] = 0;
	for(int k = 0; m >> k; k++) {
		if((m >> k & 1) == 0) continue;
		
		int cur = c % 2, to = 1 - c % 2; c++;
		dp2[to] = std::vector<i64>(t, -(1LL << 60)); dp2[0][0] = 0;
		for(int i = 0; i < t; i++) {
			for(int j = 0; j < t; j++) {
				dp2[to][(i + j) % t] = std::max(dp2[to][(i + j) % t], dp2[cur][i] + dp[k][j]);
			}
		}
	}
	
	int q; cin >> q;
	while(q--) {
		int a, b; cin >> a >> b;
		
		bool f = false;
		for(int i = a; i < t; i++) f |= b <= dp2[c % 2][i] / t;
		if(f) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 610
memory_kb: 3696
final_rank: 19

code_snippet: #include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<int>atu;
int scan(void){int h,m;cin>>h>>m;atu.pub(h*60+m);return h*60+m;}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,T,h,i,j;cin>>n>>m>>T;
	llint balls[17][1000];//合計
	for(h=0;h<=16;h++){
		for(i=0;i<T;i++){balls[h][i]=-big;}
	}
	balls[0][0]=0;
	for(i=0;i<n;i++){
		llint a;cin>>a;
		maxeq(balls[0][a%T],a);
	}
	for(h=1;h<=16;h++){
		for(i=0;i<T;i++){
			for(j=0;j<T;j++){
				maxeq(balls[h][(i+j)%T],balls[h-1][i]+balls[h-1][j]);
			}
		}
		//for(i=0;i<T;i++){cerr<<balls[h][i]<<" ";}cerr<<endl;
	}
	llint kei[1000];
	for(i=0;i<T;i++){kei[i]=-mod;}
	kei[0]=0;
	for(h=0;h<=16;h++){
		if(!(m&(1<<h))){continue;}
		llint ata[1000];
		for(i=0;i<T;i++){ata[i]=-mod;}
		for(i=0;i<T;i++){
			for(j=0;j<T;j++){
				maxeq(ata[(i+j)%T],kei[i]+balls[h][j]);
			}
		}
		swap(ata,kei);
	}
	for(i=T-1;i>0;i--){maxeq(kei[i-1],kei[i]-1);}
	
	int Q;cin>>Q;
	while(Q--){
		llint A,B;cin>>A>>B;
		cout<<(kei[A]>=(B*T+A)?"yes":"no")<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 3316
final_rank: 7