Skip to content
Archive

Kattis Challenge "Server"

“You are in charge of a server that needs to run some submitted tasks on a first-come, first-served basis. Each day, you can dedicate the server to run these tasks for at most minutes. Given the time each task takes, you want to know how many of them will be finished today.”

Kattis Challenge "Server"

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);
        }
    }
}

Related Reading

Related entries

Selected from shared tags, categories, and nearby entries in the same section.

Relationship Map

Connected Memory

This relationship map centers on the current entry and highlights connected categories and tags.

Categories 0
Tags 0
Entries 0