제출 #91538

#제출 시각아이디문제언어결과실행 시간메모리
91538SOIVIEONEBank (IZhO14_bank)C++17
44 / 100
1082 ms708 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll a[N], b[N], dp[N];
int n, m;
vi v;
void f(int id)
{
	if(id == m)
	{
		for(int i = 1; i <= n; i ++)
		{
			if(v[i] != a[i])
				return;
		}
		cout << "YES\n";
		exit(0);
	}
	ll s= 0 ;
	for(int i = 1; i <= n; i ++)
	{
		if(v[i] > a[i])
		{
			return;
		}
		s += a[i] - v[i];
	}
	if(s > dp[m-1]-dp[id-1])
	{
		return;
	}
	for(int i = 1; i <= n; i ++)
	{
		if(v[i] >= a[i])
			continue;
		v[i] += b[id];
		f(id+1);
		v[i] -= b[id];
	}
	f(id+1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	for(int i = 0; i < m; i ++)
		cin >> b[i],
		dp[i] = dp[i - 1]+b[i];
	for(int i = 0; i <= n; i ++)
		v.pb(0);
	f(0);
	cout << "NO";

	





	getchar();
	getchar();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...