#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
using namespace std;
const ll INF = 1e18, mod = 1e9 + 7, N = 2e5 + 5;
ll gcd(ll a, ll b){
if(b == 0){
return a;
}
return gcd(b, a%b);
}
ll lcm(ll a, ll b){
return (a / gcd(a,b)) * b;
}
void solve(){
ll n,m;
cin >> n >> m;
ll a[n];
vector<ll>b(m);
for(int i = 0; i < n; i++){
cin >> a[i];
}
bool test = false;
vector<ll>used(1005,0);
for(int i = 0; i < m; i++){
cin >> b[i];
used[b[i]] = 1;
}
// sort(a, a + n);
sort(all(b));
ll cur = a[0];
ll r = 1;
used[0] = 1;
for(int i = 0; i < m; i++){
if(r >= m){
break;
}
if(used[cur - b[i]]){
yes;
return;
}
ll c = b[i];
for(int j = 0; j < m; j++){
if(i == j){
continue;
}
c = b[i];
ll y = j;
for(int s = 0; s < r; s++){
c += b[y];
y++;
if(used[cur - c]){
yes;
return;
}
}
}
}
no;
}
int main() {
fast;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |