水题,由于给出的已经是单调的序列,所以有o(N)的算法
1 #include<iostream>
2 using namespace std;
3 const int MAXN=50005;
4
5
6 int main()
7 {
8 freopen("data.in","r",stdin);
9 freopen("data.out","w",stdout);
10 int c,cc,num[MAXN];
11 cin >> c;
12 for (int i=0;i<c;++i) cin >> num[i];
13 num[c]=31440461;
14 cin >> cc;
15 int p=0;
16 for (int i=0;i<cc;++i)
17 {
18 int x;
19 cin >> x;
20 while (x+num[p]<10000) ++p;
21 if (x+num[p]==10000) { cout << "YES\n"; return 0; }
22 }
23 cout << "NO\n";
24 return 0;
25 }
26