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.”

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
Ranked from shared tags, categories, and keywords, with recent section entries used as a fallback.



