Kattis Challenge "Server"

Published: August 18, 2017 | Last Modified: May 2, 2025

Tags: kattis coding challenge

Categories: Java

Problem

My solution

import java.util.Scanner;

public class KattisC {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {

            String[] nT = new String[2];

            nT = sc.nextLine().split(" ");

            int n = Integer.parseInt(nT[0]);
            int T = Integer.parseInt(nT[1]);

            int counter = 0;
            int sum = 0;

            String[] posInts = new String[30];

            posInts = sc.nextLine().split(" ");

            while (counter < n) {

                sum += Integer.parseInt(posInts[counter]);

                if (sum > T) {
                   
                    break;
                }
                counter++;

            }

            System.out.println(counter);
        }
    }
}