This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 1000010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <ll, ll>
using namespace std;
ll sum;
ll n, m;
ll v[N];
ll f[N];
ll dp[N];
ll arr[N];
int main()
{
cin >> n >> m;
for(ll i = 1; i <= n; i++) cin >> v[i], sum += v[i];
for(ll i = 1; i <= m; i++) cin >> arr[i];
ll now = 1;
for(ll i = 1; i <= n; i++) {
ll x = v[i];
while(x--) f[now++] = v[i];
}
sort(arr+1, arr+m+1);
dp[0] = 1;
for(ll i = 1; i <= m; i++)
for(ll h = sum; h >= 0; h--)
if(h + arr[i] <= sum && dp[h] == 1)
if(f[h] == f[h+arr[i]] || (f[h] != f[h+1] && f[h+arr[i]] == f[h+1]))
dp[h+arr[i]] = 1;
if(dp[sum] == 1) cout << "YES";
else cout << "NO";
}
# | 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... |