Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n; cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- int w = a[0];
- vector<int> dp(w, 2e9);
- priority_queue<pair<int, int>> pq;
- auto push = [&](int node, int dist) {
- if (dp[node] <= dist) return;
- dp[node] = dist;
- pq.emplace(-dist, node);
- };
- push(0, 0);
- while (!pq.empty()) {
- int node, dist; tie(dist, node) = pq.top(); pq.pop(); dist = -dist;
- if (dp[node] != dist) continue;
- for (int i = 0; i < n; ++i) {
- push((node + a[i]) % w, dist + a[i]);
- }
- }
- int q; cin >> q;
- while (q--) {
- int x; cin >> x;
- int ans = dp[x % w];
- if (ans <= x) {
- cout << "TAK" << '\n';
- } else {
- cout << "NIE" << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement