# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
765737 | tinhngoVN | Bank (IZhO14_bank) | C++14 | 14 ms | 33184 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>
#define MAXN 22
using namespace std;
int n,m,a[MAXN], b[MAXN];
int amt[1<<MAXN] , cnta[1<<MAXN];
//amt[i] la so tien con lai khi tra luong cho mot so nguoi o trang thai nhung to tien la i
//cnta[i] la so nguoi duoc tra luong o trang thai nhung to tien la i
void inp()
{
cin>>n>>m;
for (int i=0; i<n; ++i) cin>>a[i];
for (int i=0; i<m; ++i) cin>>b[i];
}
void out()
{
memset(amt , -1 , sizeof(amt));
memset(cnta , -1 , sizeof(cnta));
amt[0]=0; cnta[0]=0;
for (int mask=0; mask<(1<<m); ++mask)
{
for (int i=0; i<m; ++i)
{
if (mask&(1<<i))
{
int pre_mask = mask & ~(1<<i);
if(cnta[pre_mask] == -1) continue; //Neu so nguoi o trang thai truoc chua duoc tinh
int new_amt = amt[pre_mask] + b[i];
int cur = a[cnta[pre_mask]];
if(new_amt < cur)
{
cnta[mask] = cnta[pre_mask];
amt[mask] = new_amt;
}
else if (new_amt==cur)
{
cnta[mask] = cnta[pre_mask]+1;
amt[mask] = 0;
}
}
}
if(cnta[mask] == n)
{
cout<<"YES";
return ;
}
}
cout<<"NO";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
freopen("bank.inp" , "r" , stdin);
freopen("bank.out" , "w" , stdout);
inp();
out();
}
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... |