Guest User

Untitled

a guest
May 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. /*
  2. ID: vxsj.fu1
  3. LANG: JAVA
  4. PROG: baleshare
  5. */
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class baleshare {
  11.  
  12. boolean[][] jeff = new boolean[1010][1010];
  13. boolean[][] jeff2 = new boolean[1010][1010];
  14. int[] hay;
  15.  
  16. int min (int a, int b)
  17. {
  18. if (a > b)
  19. return b;
  20. return a;
  21. }
  22.  
  23. int max (int a, int b)
  24. {
  25. if (a > b)
  26. return a;
  27. return b;
  28. }
  29.  
  30. void run() throws IOException {
  31. BufferedReader f = new BufferedReader(new FileReader("baleshare.in"));
  32. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
  33. "baleshare.out")));
  34. StringTokenizer st = new StringTokenizer(f.readLine());
  35. int bales = Integer.parseInt(st.nextToken());
  36. hay = new int[bales];
  37. for (int i = 0; i < 1010; i++)
  38. {
  39. for (int j = 0; j < 1010; j++)
  40. {
  41. jeff[i][j] = false;
  42. jeff2[i][j] = false;
  43. }
  44. }
  45. jeff[0][0] = true;
  46. int sum = 0;
  47. for (int x = 0; x < bales; x++)
  48. {
  49. st = new StringTokenizer(f.readLine());
  50. hay[x] = Integer.parseInt(st.nextToken());
  51. sum += hay[x];
  52. }
  53. for (int x = 0; x < bales; x++)
  54. {
  55. for (int i = 0; i < 1010; i++)
  56. {
  57. for (int j = 0; j < 1010; j++)
  58. {
  59. jeff2[i][j] = false;
  60. }
  61. }
  62. for (int i = 0; i < 1010; i++)
  63. {
  64. for (int j = 0; j < 1010; j++)
  65. {
  66. if (i >= hay[x])
  67. {
  68. jeff2[i][j] |= jeff[i-hay[x]][j];
  69. }
  70. if (j >= hay[x])
  71. {
  72. jeff2[i][j] |= jeff[i][j-hay[x]];
  73. }
  74. }
  75. }
  76. for (int i = 0; i < 1010; i++)
  77. {
  78. for (int j = 0; j < 1010; j++)
  79. {
  80. jeff[i][j] = jeff2[i][j];
  81. }
  82. }
  83. }
  84.  
  85. int answer = 10000000;
  86. for (int i = 0; i < 1010; i++)
  87. {
  88. for (int j = 0; j < 1010; j++)
  89. {
  90. if (jeff[i][j])
  91. {
  92. answer = min(answer, max(i, max(j, sum-i-j)));
  93. }
  94. }
  95. }
  96. System.out.println(answer);
  97. out.close();
  98. System.exit(0);
  99. }
  100.  
  101. public static void main(String[] args) throws IOException {
  102. baleshare prog = new baleshare();
  103. prog.run();
  104. }
  105. }
Add Comment
Please, Sign In to add comment