This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 1
- -1
1
+ 5
Original file line number Diff line number Diff line change @@ -9,17 +9,23 @@ public class angry {
9
9
public static int N ;
10
10
11
11
public static int launchSim (int power ){
12
+ //System.out.println("Power: "+power);
12
13
int cowsUsed = 0 ;
13
14
int curCow = 0 ;
15
+ int power2 = power *2 ;
14
16
// /int lastCow = field.get(field.size() - 1);
15
17
while (curCow < N ) {
16
18
int pos = field .get (curCow );
17
19
curCow ++;
20
+ //System.out.println("Checking "+curCow + " In range "+curCow + " " + (curCow + 2 * power));
18
21
for (int i = pos ; i < N ; i ++) {
19
- if (field .get (i ) < pos + 2 * power ) {
22
+
23
+ if (field .get (i ) < pos + power2 ) {
24
+ //System.out.println(field.get(i)+" In range "+i);
20
25
curCow ++;
21
26
}
22
27
}
28
+ curCow ++;
23
29
cowsUsed ++;
24
30
}
25
31
return cowsUsed ;
@@ -37,25 +43,28 @@ public static void main(String[] args) throws IOException{
37
43
field .sort (null );
38
44
int answer = -1 ;
39
45
int l = 0 ;
40
- int r = N ;
46
+ int r = 1000000000 ;
41
47
while (r - l > 1 ) {
42
48
int m = (l + r ) / 2 ;
43
- if (launchSim (m ) > K ) {
49
+ int t = launchSim (m );
50
+ if (t < K ) {
51
+ r = m ;
52
+ }else if (K == t ) {
53
+ //System.out.println("Got it");
44
54
r = m ;
45
- } else {
55
+ //break;
56
+ }else {
46
57
l = m ;
47
58
}
48
59
}
49
60
50
- System .out .println (field );
61
+ // System.out.println(field);
51
62
//System.out.println(costs);
52
- System .out .println (l +" " +r );
63
+ // System.out.println(r +" "+l+" "+answer );
53
64
PrintWriter pw = new PrintWriter (new BufferedWriter (new FileWriter ("angry.out" )));
54
- pw .println (answer );
65
+ pw .println (r );
55
66
pw .close ();
56
- for (int i = 0 ; i < N ; i ++) {
57
- System .out .println (i +": " +launchSim (N ));
58
- }
67
+
59
68
//System.out.println("");
60
69
}
61
70
You can’t perform that action at this time.
0 commit comments