이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 100010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <int, int>
using namespace std;
int sum;
int n, m;
int v[N];
int f[N];
int dp[N];
int arr[N];
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> v[i], sum += v[i];
for(int i = 1; i <= m; i++) cin >> arr[i];
int now = 1;
for(int i = 1; i <= n; i++) {
int x = v[i];
while(x--) f[now++] = v[i];
}
dp[0] = 1;
for(int i = 1; i <= m; i++)
for(int 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... |