Roll_no_68's blog

By Roll_no_68, history, 6 hours 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;
}
  • Vote: I like it
  • -6
  • Vote: I do not like it

»
5 hours ago, # |
  Vote: I like it +4 Vote: I do not like it

This is due to the std::accumulate function. Pass the initial value as 0LL.

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you so much brother