# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31850 | ToMo01 | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 73 ms | 66244 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
2 2
2 3
5
6
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 10000007;
int cost[N], p[100007], n, Q;
vector<pair<int, int> > v;
int main(){
iostream::sync_with_stdio(false); cin.tie(0);
cin >> n >> Q;
for(int i = 1; i <= n; ++i)
cin >> p[i];
sort(p + 1, p + n + 1);
for(int i = p[n] - 1; i > 0; --i)
cost[i] = 1;
for(int i = 1; i <= n; ++i)
v.push_back({p[i], i});
int l = 0;
for(int i = 1; i < N; ++i){
if(cost[i] == 1) continue;
while(v[l].first + p[v[l].second] - 1 < i) v.push_back({v[l].first + p[v[l].second], v[l++].second});
if(v[l].first < i) cost[i] = cost[v[l].first] + 1;
else cost[i] = N;
}
while(Q--){
int x; cin >> x;
if(cost[x] == N) cout << "oo\n";
else cout << cost[x] << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |