Help me in solving PROC18A problem

My issue

My code

# cook your dish here
for x in range(int(input())):
    n,k =map(int,input().split())
    a= list(map(int,input().split()))
    totgirls=0
    summ=0
    for i in range(n-1):
        for j in range(i+1,k):
            summ+=a[j]
        tot=a[i]+summ
        if tot>totgirls:
            totgirls=tot
    print(totgirls)

Problem Link: PROC18A Problem - CodeChef

include
using namespace std;

int main() {
int t;
cin >> t;
while(t–){
int n, k;
cin >> n >> k;
int arr[n];
for(int i=0; i<n; i++) cin >> arr[i];
int windowSum=0, ans=0;
for(int i=0; i<k; i++) windowSum+=arr[i];
ans=max(ans, windowSum);
int p1=0, p2=k;
while(p2<n){
windowSum-=arr[p1];
windowSum+=arr[p2];
ans=max(ans, windowSum);
p1++, p2++;
}
cout << ans << endl;
}
return 0;
}
This is a classic Two pointers questions where you need to keep track of K length windows and max of them will be ans.