# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926152 | haru09 | Bank (IZhO14_bank) | C++17 | 104 ms | 8788 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define bit(mask,i) (((mask)>>(i))&1)
#define task "code"
const int ar=1e5+5;
const ll mod=1e9+7;
int n,m;
int a[21];
int b[21];
int need[(1<<20)];
int Left[(1<<20)];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if (fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin>>n>>m;
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
for (int i=1;i<=m;i++)
{
cin>>b[i];
}
need[0]=1;
Left[0]=0;
for (int mask=1;mask<(1<<m);mask++)
{
for (int i=0;i<m;i++)
{
if (bit(mask,i))
{
int premask=mask^(1<<i);
if (need[premask])
{
int target=a[need[premask]];
int money=b[i+1]+Left[premask];
if (money<target)
{
need[mask]=need[premask];
Left[mask]=money;
}
else if (money==target)
{
need[mask]=need[premask]+1;
Left[mask]=0;
}
}
}
}
if (need[mask]==n+1) return cout<<"YES",0;
}
cout<<"NO";
}
Compilation message (stderr)
# | 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... |