49242023-04-07 12:28:25zolmikiSípálya (55 pont)javaWrong answer 8/55509ms58944 KiB
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] readed = br.readLine().split(" ");
        int N = Integer.parseInt(readed[0]);
        int K = Integer.parseInt(readed[1]);
        int [] heights = new int[N];
        readed = br.readLine().split(" ");
        for(int i = 0; i < N; i++){
            heights[i] = Integer.parseInt(readed[i]);
        }
        br.close();

        ArrayList<Integer> list = new ArrayList<Integer>();

        int startIndex = 0;
        while(startIndex + K <= N){
            int result = 0;
            int [] currentHeights = heights.clone();
            for(int k = 0; k < K; k++){
                for(int i = startIndex + K - 1; i > startIndex; i--){
                    if(currentHeights[i] < currentHeights[i - 1] && Math.abs(currentHeights[i] - currentHeights[i - 1]) == 1){
                        continue;
                    }else if(currentHeights[i] >= currentHeights[i - 1]){
                        int difference = Math.abs(currentHeights[i] - currentHeights[i - 1]) + 1;
                        currentHeights[i - 1] += difference;
                        result += difference;
                    } else {
                        int difference = Math.abs(currentHeights[i] - currentHeights[i - 1]) - 1;
                        currentHeights[i] += difference;
                        result += difference;
                    }

                }
            }
            /*System.out.println(startIndex + "--->" + (startIndex + K - 1));
            System.out.print("[");
            for(int szam : currentHeights){
                System.out.print(szam + ", ");
            }
            System.out.print("\b\b]-->"+ result + "\n");*/
            list.add(result);
            startIndex++;
        }

        int min = Integer.MAX_VALUE;
        for(int i = 0; i < list.size(); i++){
            if(min > list.get(i)){
                min = list.get(i);
            }
        }
        System.out.println(min);
    }
}
SubtaskSumTestVerdictTimeMemory
base8/55
1Accepted0/085ms46568 KiB
2Accepted0/086ms46972 KiB
3Accepted2/2104ms57340 KiB
4Accepted2/2120ms58760 KiB
5Accepted2/2174ms58944 KiB
6Accepted2/2279ms58092 KiB
7Wrong answer0/3247ms58192 KiB
8Time limit exceeded0/1432ms41676 KiB
9Time limit exceeded0/1430ms36672 KiB
10Time limit exceeded0/1458ms35324 KiB
11Time limit exceeded0/1449ms25672 KiB
12Time limit exceeded0/1441ms25744 KiB
13Time limit exceeded0/1456ms24372 KiB
14Time limit exceeded0/2441ms24380 KiB
15Time limit exceeded0/2437ms26528 KiB
16Time limit exceeded0/2509ms51356 KiB
17Time limit exceeded0/2509ms51256 KiB
18Time limit exceeded0/2414ms51652 KiB
19Time limit exceeded0/3428ms52080 KiB
20Time limit exceeded0/2412ms51916 KiB
21Time limit exceeded0/2411ms51912 KiB
22Time limit exceeded0/2509ms51976 KiB
23Time limit exceeded0/2419ms52296 KiB
24Time limit exceeded0/2421ms53376 KiB
25Time limit exceeded0/2412ms52160 KiB
26Time limit exceeded0/2419ms52328 KiB
27Time limit exceeded0/2481ms52660 KiB
28Time limit exceeded0/3423ms52468 KiB
29Time limit exceeded0/3423ms52584 KiB
30Time limit exceeded0/3418ms52896 KiB