Google Kickstart 2019 A轮-培训代码不起作用

I am seeking to understand why the following code does not work when I put it up for submission on Google Kickstart? Here's a link to the problem.

import java.util.Scanner;

class Solution {

static int t;
static int n,p;
static Scanner sc=new Scanner(System.in);

public static int solve() {
    int[] skills = new int[n];
    for(int j=0; j<n; j++)
        skills[j]=sc.nextInt();

    // sort in descending
    for(int i=skills.length-2; i>=0; i--) {
        boolean flag=true;
        for(int j=0; j<=i; j++) {                
            if(skills[j]<skills[j+1]) {
                skills[j]+=skills[j+1];
                skills[j+1]=skills[j]-skills[j+1];
                skills[j]=skills[j]-skills[j+1];
                flag=false;
            }
        }
        if(flag)
            break;
    }

    int ans=skills[0];
    for(int i=0; i<=skills.length-p; i++) {
        int sum=0;
        int c=0;
        for(int j=i; j<=i+p-1; j++) {
            c+=skills[j];
        }
        sum += p*skills[i]-c;
        if(sum<=ans)
            ans=sum;
    }
    return ans;
}

public static void main(String[] args) {
    t=sc.nextInt();
    for(int i=1; i<=t; i++) {
        n=sc.nextInt();
        p=sc.nextInt();
        System.out.println("Case #"+i+": "+solve());
    }
}
}

当我测试给定的样本输入时,代码可以正常工作,但不适用于它们用于测试的测试集。