제출 #703921

#제출 시각아이디문제언어결과실행 시간메모리
703921Hyojin은행 (IZhO14_bank)C++17
100 / 100
104 ms8532 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...