Roll_no_68's blog

By Roll_no_68, history, 5 days ago, In English

I don't know why it's failing on test 38. Can anyone help. Also i had already defined long long as int so there is no issue of long long.

int n, m, q; cin >> n >> m >> q;
vi a(n), b(m);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
int A = accumulate(a.begin(), a.end(), 0);
int B = accumulate(b.begin(), b.end(), 0);

set<int> possA, possB;
for (auto &it : a) possA.insert(A - it);
for (auto &it : b) possB.insert(B - it);
debug(possA, possB);

while (q--) {
    int x; cin >> x;

    bool flg = 0;
    for (int i = 1; i * i <= abs(x); i++) {
       if ((x % i) != 0) continue;
       bool val1 = possA.find(i) != possA.end() && possB.find(x / i) != possB.end();
       bool val2 = possB.find(i) != possB.end() && possA.find(x / i) != possA.end();
       bool val3 = possA.find(-i) != possA.end() && possB.find(x / -i) != possB.end();
       bool val4 = possB.find(-i) != possB.end() && possA.find(x / -i) != possA.end();

       if (val1 || val2 || val3 || val4) {
         flg = 1;
         break;
       }
    }
    cout << (flg ? "YES" : "NO") << endl;
}

Full text and comments »

  • Vote: I like it
  • -6
  • Vote: I do not like it