Diagonal movement codechef solution

Diagonal movement codechef solution

Given the coordinates (x,y)(x,y) of a point in 2-D plane. Find if it is possible to reach (x,y)(x,y) from (0,0)(0,0). The only possible moves from any coordinate (i,j)(i,j) are as follows:

  • Go to the point with coordinates (i+1,j+1)(i+1,j+1).
  • Go to the point with coordinates (i+1,j1)(i+1,j−1)
  • Go to the point with coordinates (i1,j+1)(i−1,j+1).
  • Go to the point with coordinates (i1,j1

In the new world, we also have a new system called Cybalphabit system. The system assigns points to each Latin lowercase alphabet as follows:- ‘a’ is assigned 2020 , ‘b’ is assigned 2121, ‘c’ 2222 and so on. Thus, finally ‘z’ is assigned 225225 points.

A Cyberstring is a sequence of lowercase Latin alphabets.

Now, the total score of a Cyberstring will be the sum of points of its characters. You will be given two integers NN and KK. Construct a Cyberstring XX of length NN with total score KK or print 1−1 if it is not possible to form the Cyberstring (XX). If there are multiple answers, print any.


  • First line contains TT, the number of test cases.
  • Each of the next TT lines denotes a different test case :
  • The (i+1)th(i+1)th line denotes the ithith test case, and contains two integers NN and KK, the length of the string that is to be constructed, and the score of the string respectively.


  • For each test case, provide the output on a different line.
  • Output the required string XX, if one exists, otherwise output 1−1.


  • 1T1051≤T≤105
  • 1n1051≤n≤105
  • 1k51071≤k≤5∗107

The sum of nn over all test cases is less than 105105

Sample Input:

2 2
2 5
4 5
3 2

Expected Output:



In the first test case, n=2n=2 and k=2k=2. So,we have to construct a string of length 22 with total score 22. It can be easily seen that the only possible string is “aa”. Its total score will be equal to 20+20=220+20=2.

In the second case, “ac” will have score 20+22=520+22=5. Obviously, “ca” will also have the same score and is also a possible answer.

In the fourth test case, it can be shown that there is no possible string which satisfies the conditions.




Diagonal movement codechef solution

Leave a Comment