http://oj.jxust.edu.cn/problem.php?id=1274
#include <iostream> #include <set> using namespace std; int main() { int n, m; cin >> n >> m; set<int> a; set<int> b; set<int> ::iterator it = a.begin(); //set<int> ::iterator ite = b.end(); for(int i = 0; i < n; i++) { int h; cin >> h; a.insert(h); } for(int i = 0; i < m; i++) { int h; cin >> h; b.insert(h); } it = a.begin(); //ite = b.end(); int k; cin >> k; while(k--) { int x; cin >> x; int falg = 0; for(it = a.begin(); it != a.end(); it++) { int aim = x - *it; if(b.find(aim) != b.end()) { falg = 1; cout << "Yes" << endl; break; } } /*while(1) { if((*it + *ite) == x) { cout << "Yes" << endl; break; } else if(*it + *ite > x) { ite--; } else if(*it + *ite < x) { it++; } if((it == a.end() && ite == b.end()) || (it == a.begin() && ite == b.end())) { falg = 1; break; } }*/ if(!falg) { cout << "No" << endl; } } return 0; }