Submission #5976819


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[] rightSumArray = new long[n];
        for (int i=0; i<n; i++){
            if (i==0){
                rightSumArray[0] = valueArray[n-1];
            }else {
                rightSumArray[i] = rightSumArray[i-1] + valueArray[n-1-i];
            }
        }

        long yoyuu = leftSumArray[n-1] - k;
        int genkaiIndexFromLeft = 0;
        for (int i=0; i<n; i++){
            if (leftSumArray[i] > yoyuu){
                genkaiIndexFromLeft = i;
                break;
            }
        }
        int genkaiIndexFromRight = 0;
        for (int i=0; i<n; i++){
            if (rightSumArray[i] > yoyuu){
                genkaiIndexFromRight = i;
                break;
            }
        }

        long answerCount = 0L;

        for (int i=0; i<=genkaiIndexFromLeft; i++){
            long sum = 0L;
            for (int j=i; j<n; j++){
                sum += valueArray[j];
                if (sum >= k){
                    answerCount+= n-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 1699 Byte
Status
Exec Time 1978 ms
Memory 60236 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 93 ms 21844 KB
02.txt 94 ms 19156 KB
03.txt 94 ms 19284 KB
04.txt 93 ms 16980 KB
05.txt 94 ms 19284 KB
06.txt 94 ms 19284 KB
07.txt 94 ms 18900 KB
08.txt 95 ms 20688 KB
09.txt 95 ms 19284 KB
10.txt 95 ms 19412 KB
11.txt 94 ms 19412 KB
12.txt 97 ms 21076 KB
13.txt 93 ms 19924 KB
14.txt 1687 ms 47360 KB
15.txt 1176 ms 48408 KB
16.txt 1473 ms 48972 KB
17.txt 744 ms 48836 KB
18.txt 1040 ms 60236 KB
19.txt 1063 ms 47736 KB
20.txt 1978 ms 49540 KB
21.txt 526 ms 58408 KB
22.txt 1218 ms 50904 KB
23.txt 453 ms 47232 KB
24.txt 418 ms 50076 KB
25.txt 428 ms 48456 KB
26.txt 712 ms 47280 KB
s1.txt 93 ms 21844 KB
s2.txt 92 ms 19284 KB
s3.txt 93 ms 19028 KB