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