Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions ColorThePicture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//COLOR THE PICTURE

#include<bits/stdc++.h>
using namespace std;

void solve(){

//the picture will be strip of rows with col more than 2 or strip of cols with row more than 2

int n,m,k;
cin >> n >> m >> k;

vector<int> a(k);

for(int i=0;i<k;i++) cin >> a[i];

long long cols = 0;
int flag = 0;
for(int i=0;i<k;i++){
if(a[i]/n > 2) flag = 1;
if(a[i]/n >=2) cols += a[i]/n;
}

if(cols >= m && (flag || m%2==0)){
cout << "YES" << endl;
return;
}

long long rows = 0;
flag = 0;
for(int i=0;i<k;i++){
if(a[i]/m > 2) flag = 1;
if(a[i]/m >=2) rows += a[i]/m;
}

if(rows >= n && (flag || n%2==0)){
cout << "YES" << endl;
return;
}

cout << "NO" << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

int t;
cin>>t;

while(t--)
{
solve();
}

cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}