Help me in solving ARRAYARR1 problem

My issue

as I can assign int cost value on more than one place and it will be correct as e.g. I can put it after cin>>x>>n; also after completion of the first loop but it will show wrong answer for this places

Learning course: Arrays using C++
Problem Link: CodeChef: Practical coding for everyone

@pritulraut9031
yeah this is also correct , but for these types of problems U have to rearrange as it is given.

Why showing partially correct ans although my code is giving correct output?
Question:CodeChef: Practical coding for everyone
Code:
n=int(input())
l=list(map(int,input().split()))
s=0
for i in range(n):
for j in range(i,n):
d=abs(l[i]-l[j])
s+=d
print(s)

@shubhmadaan31
to remove the tle just precompute the prime palindromic numbers till 10^5 before the test case loop and store it in some data structure .
and then use that ds inside test case loop.

1 Like

we have to use queue data structures first we have to do enqueue int queue
and after second step we have to dequeue we print deque elements and enqueue
whether it is a palindrome or not

and then use that ds inside test case loop.