https://www.codechef.com/viewsolution/26842251
Question: PAIRSUM2
Contest: LTIME76B
Please review my Solution. This solution didn’t get accepted in the contest. Please review it.
{A} is not always an equal-difference sequence.
So you can’t just printf("%lld",B[d-1]);
3 Likes
B is the resultant array of A where B[i] = A[i]+A[i+1] for 0<i<=N
B will always be equal difference cuz A is a sequence.
Nevertheless could you please give me a Example.
I got it.
Thanks mate again
2 Likes



#include <iostream>
using namespace std;
int main() {
int t, *p;
cin >> t;
while(t--){
int n, q;
cin >> n >> q;
p = new int[n - 1];
for (int i = 0;i < (n - 1);i++)
cin >> p[i];
while (q--) {
int a, b;
cin >> a >> b;
int k;
k = a - b;
k = abs(a - b);
if (k ==1 ) {
int m;
a < b ? m = a : m = b;
cout << p[m-1] << endl;
}
else if (k % 2 == 0) {
cout << "UNKNOWN" << endl;
}
else {
int res=0;
int* e = NULL ;
a < b ? e = &p[a-1] : e = &p[b-1];
for (int h = 1;h < k;h++)
e++;
for (int s = 0;s < k;s++) {
if (s % 2 == 1) {
res = res - (*e);
}
if (s % 2 == 0) {
res = res + (*e);
}
e--;
}
cout << res << endl;
}
}
}
}
Bro , can you give the test case for WA ?