1711C - Color the Picture - CodeForces Solution


constructive algorithms greedy *1500

Please click on ads to support us..

Python Code:

import math as mt
from collections import defaultdict,deque
from bisect import bisect_left as b_l
from bisect import bisect_right as b_r
import sys

mod=10**9+7


for _ in range(int(input())):
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    if(n==1 or m==1):
        print("No")
        continue
    else:
        a.sort(reverse=True)

        total=m
        if(total&1):flag=False
        else:flag=True
        for i in a:
            if(total&1):
                if((i//n)>=3):
                    flag=True
            if((i//n)>1):
                total-=(i//n)
        if(total<=0 and flag):
            print("Yes")
            continue

        total=n
        if(total&1):flag=False
        else:flag=True
        for i in a:
            if(total&1):
                if((i//m)>=3):
                    flag=True
            if((i//m)>1):
                total-=(i//m)
        if(total<=0 and flag):
            print("Yes")
            continue

        print("No")
            

C++ Code:

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    for (int test=0;test<t;test++)
    {
        ll n,m,k;
        cin>>n>>m>>k;
        ll am =0;
        bool am1=false;
        ll an =0;
        bool an1=false;
        for(int i=0;i<k;i++)
        {
            ll ai;
            cin>>ai;
            ll amm = ai/n;
            if(amm>1)
            {
                am+=amm;
            }
            am1 = am1 || (amm>2);
            ll ann = ai/m;
            if(ann>1)
            {
                an+=ann;
            }
            an1 = an1 || (ann>2);
        }
        cout<<(((am>=m && (am1 || m%2==0)) || (an>=n && (an1 || n%2==0)))?"Yes":"No")<<endl;

    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement
903A - Hungry Student Problem
52B - Right Triangles
1712A - Wonderful Permutation
1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations