Submission #6107964


Source Code Expand

Copy
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] valueArray = new long[n];
        long[] leftSumArray = new long[n];

        for (int i=0; i<n; i++){
            valueArray[i] = sc.nextInt();

            if (i == 0) {
                leftSumArray[0] = valueArray[0];
            }else {
                leftSumArray[i] = leftSumArray[i-1] + valueArray[i];
            }
        }

        long answerCount = 0L;
        int rightIndex = 0;

        for (int i=0; i<n; i++){
            long sum = 0L;
            for (int j=rightIndex; j<n; j++){
                sum = leftSumArray[j] - leftSumArray[i] + valueArray[i];
                if (sum >= k){
                    answerCount+= n-j;
                    rightIndex = j;
                    break;
                }
            }
        }

        System.out.println(answerCount);
    }
}

Submission Info

Submission Time
Task D - Enough Array
User alkwest
Language Java8 (OpenJDK 1.8.0)
Score 400
Code Size 1045 Byte
Status
Exec Time 460 ms
Memory 59128 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 97 ms 21712 KB
02.txt 94 ms 19796 KB
03.txt 97 ms 23124 KB
04.txt 95 ms 18900 KB
05.txt 101 ms 21716 KB
06.txt 98 ms 18900 KB
07.txt 96 ms 18644 KB
08.txt 99 ms 20564 KB
09.txt 100 ms 21588 KB
10.txt 96 ms 19924 KB
11.txt 99 ms 19664 KB
12.txt 100 ms 19540 KB
13.txt 108 ms 21716 KB
14.txt 355 ms 50012 KB
15.txt 377 ms 48200 KB
16.txt 429 ms 49252 KB
17.txt 397 ms 45120 KB
18.txt 375 ms 59128 KB
19.txt 396 ms 46936 KB
20.txt 446 ms 47272 KB
21.txt 409 ms 50956 KB
22.txt 421 ms 50464 KB
23.txt 429 ms 46676 KB
24.txt 435 ms 49292 KB
25.txt 417 ms 47284 KB
26.txt 460 ms 47052 KB
s1.txt 96 ms 19796 KB
s2.txt 96 ms 21716 KB
s3.txt 98 ms 22996 KB