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

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;
}

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;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Do crabs foam at the mouth?

If you have ever spent time exploring coastal shores, tide pools, or beaches, you may have encountered a crab producing a thick cluster of...

The Real Truth About Viral Kitchen Gadgets Before You Buy

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

Voltage imaging of neurons distributed across entire brains of larval zebrafish – Nature

In a groundbreaking advancement for neuroscience, researchers have developed an innovative high-speed optical microscopy platform capable of recording electrical activity across the entire brain...

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!