RRSTONE - Editorial

I have used long int only and the solution is absolutely fine…don`t forget to add the corner case when number of turns(k) == 0


#define s(a) scanf("%ld",&a)
#define max(a,b) a >= b ? a : b
#define min(a,b) a <= b ? a : b
#define S 102400
typedef long int li;

int main()

li k,n,arr[S],i,min_no = INT_MAX, max_no = 0;

s(n); s(k);

for(i=0; i<n; i++){
	min_no = min(min_no,arr[i]);
	max_no = max(max_no,arr[i]);

if(k == 0){
	for(i=0; i<n; i++)
		printf("%ld ",arr[i]);
else if( k % 2==0){
	for(i=0; i<n; i++)
		printf("%ld ",arr[i] - min_no);
	for(i=0; i<n; i++)
		printf("%ld ",max_no - arr[i]);

return 0;


Can Anyone tell me why it is giving wa?


Solution in C++, you just need 2 little lines:

long long max = *max_element(A.begin(), A.end());
transform(A.begin(), A.end(), A.begin(), bind1st(minus(), max));

Full solution can be viewed here.

Hope that helps!

my code was working fine…but even though codechef was showing wrong result.why???
My solution can be findd here-

Really? So you can tell me, what is wrong here - http://ideone.com/HeY1vh

How can that relate to wrong result?? If i have used long long int,but my results are correct,then whats the problem?(and within the time limit)

The guywho told to use long int deleted his comment??? Somebody Give a correct reason please…

You should print the array after K steps, but you are not - http://ideone.com/k97Ksn

reason is above - the test case and in link I provided in comment you can see what happens when integer overflow occurs…

i have used long long int,not long int…!!!just tell me,for which case my code fails?

edit your code to long long int,and then see its printing 4000000000.
you have declared in long int and is using %lld,thats why your code is showing wron results…see here http://ideone.com/4zMwOB

but my comment was for the guy telling, that long int is ok, which is not in our environment…

whats wrong with my code?? codechef is showing wrong result.

Mine is here - http://www.codechef.com/viewsolution/3830766

Your last submission return “null” for input

2 0
-2000000000 2000000000

I think, that problem is in

long long int *A=(long long int *)calloc(n,sizeof(int));
// notice the sizeof(int)

but I didn’t find the input I can show you on IdeOne…


2 2
1 2

expected output is 0 1, because {1, 2} -> {1, 0} -> {0, 1}

your code returns 1 2 (http://ideone.com/WfXwGy )

@saurabh8c, I do not agree with your on your first paragraph, it’s not sadistic, in programming contests you always have to check what the worst case scenario will be like (even though it could be very hard on some problems). These are very common things in programming contests, there are also authors that specify if the answer can be held by a certain data type even though usually it’s not mandatory.

Thank you.
I have found my mistake in the code.
I want to ask few newbie doubts related to competitive programing.
I request you to please guide me for the same as to where can I ask them.

Do you mind if I drop you a PM.

Thank you.

this is ur corrected code…http://www.codechef.com/viewsolution/3905612 the problem was that u were using 1 based indexing…so the the (10^5)th number was getting stored at a mem location that wasnt defined…and hence maybe was being replaced by garbage values so u had to declare an array of size (10^5)+1…hope this helps…:slight_smile: