2 import java
.util
.Arrays
;
3 import java
.util
.Scanner
;
6 * @author Vladimir Danilov
8 public class javacert_vd
implements Runnable
{
10 private static final String FILE_NAME
= "javacert";
11 private static final int MAX_VALUE
= Integer
.MAX_VALUE
/ 2;
16 } catch (Throwable t
) {
23 private PrintWriter out
;
25 private void solve() throws Exception
{
26 in
= new Scanner(new FileReader(FILE_NAME
+ ".in"));
27 out
= new PrintWriter(new File(FILE_NAME
+ ".out"));
29 int[][] rev
= new int[101][101];
31 for (int i
= 0; i
<= 100; i
++) {
32 for (int j
= 0; j
<= 100; j
++) {
33 rev
[i
][j
] = errorCount(i
, j
);
41 int [] perc
= new int[n
];
42 for (int i
= 0; i
< m
; i
++) {
43 perc
[i
] = in
.nextInt();
48 int result
= MAX_VALUE
;
50 int [] resCount
= new int[m
];
51 int [] resErrors
= new int[m
];
53 for (int min
= 1; min
<= n
/ m
; min
++) {
54 int[][][] d
= new int[m
+ 1][n
+ 1][n
+ 1];
57 Arrays
.fill(c
, MAX_VALUE
);
61 int [][][] candCount
= new int[m
+ 1][n
+ 1][n
+ 1];
62 int [][][] candErrors
= new int[m
+ 1][n
+ 1][n
+ 1];
66 for (int i
= 0; i
< m
; i
++) {
67 for (int processed
= min
* i
; processed
<= n
; processed
++) {
68 for (int errors
= 0; errors
<= processed
; errors
++) {
69 if (d
[i
][processed
][errors
] == MAX_VALUE
) {
72 int max
= n
- processed
;
73 for (int count
= min
; count
<= max
; count
++) {
74 int newCount
= processed
+ count
;
75 int add
= rev
[perc
[i
]][count
];
77 int newErrors
= errors
+ add
;
78 int cand
= Math
.max(d
[i
][processed
][errors
], count
);
79 if (cand
< d
[i
+ 1][newCount
][newErrors
]) {
80 d
[i
+ 1][newCount
][newErrors
] = cand
;
81 candCount
[i
+ 1][newCount
][newErrors
] = count
;
82 candErrors
[i
+ 1][newCount
][newErrors
] = add
;
90 if (d
[m
][n
][err
] != MAX_VALUE
&& result
> d
[m
][n
][err
] - min
) {
93 for (int i
= m
; i
> 0; i
--) {
94 resCount
[i
- 1] = candCount
[i
][curCount
][curErrors
];
95 resErrors
[i
- 1] = candErrors
[i
][curCount
][curErrors
];
97 curCount
-= resCount
[i
- 1];
98 curErrors
-= resErrors
[i
- 1];
101 result
= d
[m
][n
][err
] - min
;
105 for (int i
= 0; i
< m
; i
++) {
106 out
.printf("%d %d\n", resErrors
[i
], resCount
[i
]);
113 private int errorCount(int percentage
, int questionCount
) {
114 int right
= Math
.max((percentage
* questionCount
) / 100, 0);
116 long resP
= countPercentage(questionCount
, right
);
117 if (resP
== percentage
) {
118 return questionCount
- right
;
120 if (resP
> percentage
) {
127 private long countPercentage(int questionCount
, int right
) {
128 if (questionCount
> 0 && (right
* 200) % questionCount
== 0) {
129 int floor
= (right
* 100) / questionCount
;
130 if ((right
* 100) % questionCount
== 0) {
133 return floor
+ (floor
% 2);
135 double a
= (100.0 * right
/ questionCount
);
136 return Math
.round(a
);
139 public static void main(String
[] args
) {
140 new Thread(new javacert_vd()).start();