Codeforces Round #386 (Div. 2), problem: (D) Green and Black Tea Solution in C/C++

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

Codeforces Round #386 (Div. 2), problem: (D) Green and Black Tea Solution in C/C++

#include<stdio.h>
int main()
{
    long long n,k,a,b,i;
	char x='G',y='B';
	int num=0;
	scanf("%I64d%I64d%I64d%I64d",&n,&k,&a,&b);
	if(a>b)
	{
		int t=a;a=b;b=t;
		char z=x;x=y;y=z;
	}
	if(b>(a+1)*(k)) {
		printf("NO\n");
		return 0;
	}
	for(i=0;i<n;i++){
		if(b>a&&num<k){printf("%c",y);b--;num++;}
		else {printf("%c",x);a--;num=0;}
	}
	return 0;
}

📦 Looking for Codeforces Round 386 Div Problem Green? Check the best deals on Amazon.

🛒 Shop Codeforces Round 386 Div Problem Green on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

Codeforces Round #386 (Div. 2), problem: (D) Green and Black Tea Solution in C/C++

#include<stdio.h>
int main()
{
    long long n,k,a,b,i;
	char x='G',y='B';
	int num=0;
	scanf("%I64d%I64d%I64d%I64d",&n,&k,&a,&b);
	if(a>b)
	{
		int t=a;a=b;b=t;
		char z=x;x=y;y=z;
	}
	if(b>(a+1)*(k)) {
		printf("NO\n");
		return 0;
	}
	for(i=0;i<n;i++){
		if(b>a&&num<k){printf("%c",y);b--;num++;}
		else {printf("%c",x);a--;num=0;}
	}
	return 0;
}

📦 Looking for Codeforces Round 386 Div Problem Green? Check the best deals on Amazon.

🛒 Shop Codeforces Round 386 Div Problem Green on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Lil Durk Found Not Guilty in Federal Murder-for-Hire Trial

In a dramatic conclusion to one of the hip-hop community's most closely watched legal battles, Chicago rapper Lil Durk has been found not guilty...

The Ultimate Viral Kitchen Gadgets Guide You Didnt Know You Needed

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!