I directly took the first element of the score difference array. I am taking the number of shots of each player next to them and subtracting the number of shot everytime I move by one square from the first element score. Also, everytime I pass a shot I change the counter by two because the bullseye will now move away from the shot instead of towards but the code is failing some hidden test case. Can someone please help me? include <bits/stdc++.h>
using namespace std;

int main() {
int T,N,M,scorea,scorek,counta,countk;
cin >> T;
while (T) {
scorea=0;
scorek=0;
countk=0;
counta=0;
cin >> N >> M;
vector A(M,0);
for (int i=0;i<M;i++) {
cin >> A[i];
}
for (int i=0;i<M;i++) {
if(A[i]==1||A[i]==3) {
counta-=1;
scorea+=i;
}
if(A[i]==2||A[i]==3) {
countk-=1;
scorek+=i;
}
}
vector B(M,0);
for (int i=0;i<M;i++) {
B[i]=abs(scorea-scorek);
if(A[i]==1||A[i]==3) {
counta+=2;
}
if (A[i]==2||A[i]==3) {
countk+=2;
}

Score Calculation Logic: The score should be based on the positions of shots, but your handling of score adjustment during iteration might not be correct.

Updating Counts: The way youâ€™re updating counta and countk could lead to incorrect calculations, particularly how youâ€™re incrementing or decrementing them based on shots.

Score Difference Logic: You calculate the score difference for every shot, but youâ€™re not correctly reflecting how the â€śbullseyeâ€ť concept works.

Suggested Approach

Initialize Scores Properly: Start from zero for both players and calculate the total score as you iterate through each shot.

Iterate and Update Correctly: For each shot, check its type and update the respective score accordingly. Also, adjust the counts as you pass each shot.

Maintain Score Differences: Store the difference in scores correctly as you progress.

Hereâ€™s a corrected version of your code with explanations inline:

#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int N, M;
cin >> N >> M;
vector<int> A(M);
for (int i = 0; i < M; i++) {
cin >> A[i];
}
long long scoreA = 0, scoreK = 0;
vector<long long> B(M);
for (int i = 0; i < M; i++) {
// Calculate the scores based on the shot type
if (A[i] == 1 || A[i] == 3) {
scoreA += i;
}
if (A[i] == 2 || A[i] == 3) {
scoreK += i;
}
// Store the current score difference
B[i] = abs(scoreA - scoreK);
}
for (int i = 0; i < M; i++) {
cout << B[i] << " ";
}
cout << endl;
}
return 0;
}

Key Changes

Removed Count Variables: You donâ€™t need separate counters (counta, countk) for the logic youâ€™re implementing.

Directly Updated Scores: Directly update scoreA and scoreK without intermediary count adjustments, as they should reflect the shot scores directly.

Used Long Long for Scores: Itâ€™s safer to use long long for scores in case of large inputs, although it might not be strictly necessary here.

Explanation of the Logic

For each shot type (1, 2, or 3), you increment the respective playerâ€™s score by the index of the shot.

The absolute difference in scores is calculated and stored for each shot.

At the end of processing all shots, the score differences are printed.

This should address the hidden test cases you were encountering. Make sure to test it with various scenarios to ensure correctness!