Submission #640226

#TimeUsernameProblemLanguageResultExecution timeMemory
640226Zian_JacobsonBank (IZhO14_bank)C++17
19 / 100
101 ms8532 KiB
#include<bits/stdc++.h>
using namespace std;
#define cIO ios_base::sync_with_stdio(0);cin.tie(0)
#define fileIO(x) ifstream fin(string(x)+".in"); ofstream fout(string(x)+".out")
#define cont(container, object) (container.find(object)!=container.end())
#define sz(x) (int) (x).size()
#define ll long long
#define v vector
int ppl_cvr[1 << 20], leftover[1 << 20];
int N, M;

int main()
{
	fill_n(ppl_cvr, 1 << 20, -1);
	fill_n(leftover, 1 << 20, 0);
	cin >> N >> M;
	vector<int> ppl(N, 0);
	vector<int> notes(M, 0);
	for (int i = 0; i <= N - 1; i++) cin >> ppl[i];
	ppl.push_back(10000000);//to prevent overflow
	for (int i = 0; i <= M - 1; i++) cin >> notes[i];
	for (int msk = 1; msk < (1 << M); msk++)
	{
		if (msk == 20)
		{
			int sadf = 1;
		}
		for (int nt = 0; nt <= M - 1; nt++)
		{
			
			if (msk & (1 << nt))
			{
				if (ppl[ppl_cvr[msk - (1 << nt)] + 1]
					== notes[nt] + leftover[msk - (1 << nt)])//if exactly enough for the next person
				{
					ppl_cvr[msk] = ppl_cvr[msk - (1 << nt)] + 1;
					leftover[msk] = 0;
				}
				else
				{
					ppl_cvr[msk] = max(ppl_cvr[msk], ppl_cvr[msk - (1 << nt)]);
					leftover[msk] = leftover[msk - (1 << nt)] + notes[nt];
				}
			}
		}
	}
	if (ppl_cvr[(1 << M) - 1] == N - 1) cout << "YES";
	else cout << "NO";
	return 0;
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:26:8: warning: unused variable 'sadf' [-Wunused-variable]
   26 |    int sadf = 1;
      |        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...