이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define bit(n,i) ((n>>i)&1)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
#define ll long long
const int MOD=1e9+7;
const int base=31;
const int N=1e6+5;
int n,m,leftover[1<<20],num_people[1<<20],bank[20],salary[20];
int main()
{
#ifdef Hyojin
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif //Hyojin
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for (int i=0;i<n;i++) cin>>salary[i];
for (int i=0;i<m;i++) cin>>bank[i];
memset(num_people,-1,sizeof num_people);
memset(leftover,-1,sizeof leftover);
leftover[0]=num_people[0]=0;
for (int mask=0;mask<(1<<m);mask++)
{
for (int i=0;i<m;i++)
{
if (bit(mask,i))
{
int premask=mask-(1<<i);
if (num_people[premask]==-1) continue;
int total=leftover[premask]+bank[i];
int cur=salary[num_people[premask]];
if (total<cur)
{
leftover[mask]=total;
num_people[mask]=num_people[premask];
}
if (total==cur)
{
leftover[mask]=0;
num_people[mask]=num_people[premask]+1;
}
}
}
if (num_people[mask]==n)
{
cout<<"YES";
return 0;
}
}
cout<<"NO";
return 0;
}
# | 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... |