이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5 + 10, MAX = 1e4 + 10, mod = 1e9 + 7, inf = 1e9 + 10; //////
int a[maxn], dp[MAX];
set<pii> st;
priority_queue<pii, vector<pii>, greater<pii> > pq;
vector<int> vec;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int n, q;
cin >> n >> q;
int lm = 1;
for(int i = 0; i < n; i++){
cin >> a[i];
lm = min(1ll * lm * a[i], ll(MAX));
pq.push({0, a[i]});
st.insert({1, a[i]});
}
for(int i = 0; i < lm; i++){
vec.clear();
while(!pq.empty() && pq.top().F == i){
int p = pq.top().S;
vec.PB(p);
pq.pop();
st.erase({dp[i-p] + 1, p});
}
if(i > 0)
assert(sz(st)), dp[i] = st.begin()->F;
for(int x : vec){
st.insert({dp[i] + 1, x});
pq.push({i + x, x});
}
}
while(q--){
int x;
cin >> x;
if(x >= lm)
cout << "oo\n";
else
cout << dp[x] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |