import java.io.*; import java.util.*; /** * Use dynamic programming. Keep track of whether or not we can reach i minutes * on disk 1 and j minutes on disk 2. * But this solution is incorrect in that it does not minimise the difference in * minutes on the two disks. * * @author Finn Lidbetter */ public class no_difference_minimisation { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s = br.readLine().split(" "); int C = Integer.parseInt(s[0]); int n = Integer.parseInt(s[1]); // dp[i][j] is true iff we can get i minutes used on disk 1 and // j minutes used on disk 2. boolean[][] prev = new boolean[C+1][C+1]; prev[0][0] = true; s = br.readLine().split(" "); for (int i=0; ibest || (i+j==best && i>bestD1)) { best = i+j; bestD1 = i; bestD2 = j; } } } System.out.println(bestD1 + " " + bestD2); } }