Rezultati

Up. imeNalogaJezikRezultatČas oddaje
sts-koper-2019 Kuponi za pice Java 100/100OK 24. apr '19 @ 18:35

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 16/16 57,066 MiB 0,177 s OK
#2 [več] 16/16 52,977 MiB 0,000 s OK
#3 [več] 17/17 60,094 MiB 0,273 s OK
#4 [več] 17/17 65,598 MiB 0,559 s OK
#5 [več] 17/17 63,246 MiB 0,380 s OK
#6 [več] 17/17 61,801 MiB 0,194 s OK

Ocenjevani program (PizzaVouchers.java):
import java.io.*;
import java.util.*;

public class PizzaVouchers {
	
	public static int maximums[], cases, vouchers;
	public static long sum = 0;

	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String firstLine = reader.readLine();
		cases = Integer.parseInt(firstLine.split(" ")[0]);
		vouchers = Integer.parseInt(firstLine.split(" ")[1]);
		maximums = new int[cases];
		
		for (int i = 0; i < cases; i++) {
			String data[] = reader.readLine().split(" ");
			int temp[] = new int[data.length];
			for (int j = 0; j < data.length; j++) {
				temp[j] = Integer.parseInt(data[j]);
			}
			maximums[i] = findMax(temp);
		}
		
		Arrays.sort(maximums);
		for (int i = 0; i < vouchers; i++) {
			sum += maximums[i];
		}
		
		System.out.println(sum);
		
	}
	
	public static int findMax(int arr[]) {
		int max = arr[0];
		for (int i = 1; i < arr.length; i++) max = Math.max(max, arr[i]);
		return max;
	}

}