Language: Java

public class Main {
	static int s;
	static int d;
	static int m;
	static Map<Integer,Kanmi> Fmap = new HashMap<>();
	public static void main(String[] args) {
		while(true){
			Scanner scan = new Scanner(System.in);
			String s = scan.next();
			if(s.equals("EOF")){
				break;
			}
			Main.s = new Integer(s);
			Main.d = scan.nextInt();
			Main.m = scan.nextInt();
			ArrayList<Kanmi> list = new ArrayList<>();
			for(int i = 0;i < Main.s;i++){
				ArrayList<Integer[]> wp = new ArrayList<>();
				int k = scan.nextInt();
				for(int j = 0;j < k;j++){
					wp.add(new Integer[]{scan.nextInt(),scan.nextInt()});
				}
				list.add(new Kanmi(k,wp));
			}
			for(int i = 0;i < Main.d;i++){
				Main.Fmap.put(i,list.get(scan.nextInt()));
				Main.dp.put(i,new HashMap<>());
			}
			int[] ans = Main.rec(0,Main.m, 0);
			System.out.println(ans[1] + " " + (Main.m - ans[0]));
		}
	}
	static Map<Integer,Map<Integer,int[]>> dp = new HashMap<>();
	public static int[] rec(int day,int money,int weight){
		if(money < 0){
			return new int[]{Integer.MAX_VALUE,0};
		}
		if(day >= Main.d){
			return new int[]{money,weight};
		}
		if(Main.dp.get(day).containsKey(money)){
			return Main.dp.get(day).get(money);
		}
		int[] max = new int[]{Integer.MAX_VALUE,0};
		for(Integer[] e : Main.Fmap.get(day).wp){
			int[] r = Main.rec(day+1, money-e[1], weight+e[0]);
			if(max[1] <= r[1] && max[0] > r[0]){
				max = r;
			}
		}
		Main.dp.get(day).put(money, max);
		return max;
	}
	static class Kanmi{
		int k;
		ArrayList<Integer[]> wp;
		public Kanmi(int k,ArrayList<Integer[]> wp){
			this.k = k;
			this.wp = wp;
		}
	}
}

Compiler output:
Main.java:5: error: cannot find symbol
	static Map<Integer,Kanmi> Fmap = new HashMap<>();
	       ^
  symbol:   class Map
  location: class Main
Main.java:33: error: cannot find symbol
	static Map<Integer,Map<Integer,int[]>> dp = new HashMap<>();
	       ^
  symbol:   class Map
  location: class Main
Main.java:33: error: cannot find symbol
	static Map<Integer,Map<Integer,int[]>> dp = new HashMap<>();
	                   ^
  symbol:   class Map
  location: class Main
Main.java:56: error: cannot find symbol
		ArrayList<Integer[]> wp;
		^
  symbol:   class ArrayList
  location: class Kanmi
Main.java:57: error: cannot find symbol
		public Kanmi(int k,ArrayList<Integer[]> wp){
		                   ^
  symbol:   class ArrayList
  location: class Kanmi
Main.java:5: error: cannot find symbol
	static Map<Integer,Kanmi> Fmap = new HashMap<>();
	                                     ^
  symbol:   class HashMap
  location: class Main
Main.java:8: error: cannot find symbol
			Scanner scan = new Scanner(System.in);
			^
  symbol:   class Scanner
  location: class Main
Main.java:8: error: cannot find symbol
			Scanner scan = new Scanner(System.in);
			                   ^
  symbol:   class Scanner
  location: class Main
Main.java:13: warning: [removal] Integer(String) in Integer has been deprecated and marked for removal
			Main.s = new Integer(s);
			         ^
Main.java:16: error: cannot find symbol
			ArrayList<Kanmi> list = new ArrayList<>();
			^
  symbol:   class ArrayList
  location: class Main
Main.java:16: error: cannot find symbol
			ArrayList<Kanmi> list = new ArrayList<>();
			                            ^
  symbol:   class ArrayList
  location: class Main
Main.java:18: error: cannot find symbol
				ArrayList<Integer[]> wp = new ArrayList<>();
				^
  symbol:   class ArrayList
  location: class Main
Main.java:18: error: cannot find symbol
				ArrayList<Integer[]> wp = new ArrayList<>();
				                              ^
  symbol:   class ArrayList
  location: class Main
Main.java:27: error: cannot find symbol
				Main.dp.put(i,new HashMap<>());
				                  ^
  symbol:   class HashMap
  location: class Main
Main.java:33: error: cannot find symbol
	static Map<Integer,Map<Integer,int[]>> dp = new HashMap<>();
	                                                ^
  symbol:   class HashMap
  location: class Main
14 errors
1 warning