This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -13,22 +13,25 @@ public static int launchSim(int power){
13
13
int cowsUsed = 0 ;
14
14
int curCow = 0 ;
15
15
int power2 = power *2 ;
16
+ int l ,range ;
16
17
// /int lastCow = field.get(field.size() - 1);
17
18
while (curCow < N ) {
18
19
cowsUsed ++;
19
20
int pos = field .get (curCow );
20
- // curCow++ ;
21
+ l = curCow + 1 ;
21
22
23
+ range =0 ;
22
24
//System.out.println("Checking "+curCow + " In range "+curCow + " " + (curCow + 2 * power));
23
- for (int i = pos ; i < N ; i ++) {
25
+ for (int i = l ; i < N ; i ++) {
24
26
25
- if (field .get (i ) < ( pos + power2 ) ) {
27
+ if (field .get (i ) <= pos + power2 ) {
26
28
//System.out.println(field.get(i)+" In range "+i);
27
- curCow ++;
29
+ range ++;
28
30
}
29
31
}
30
- curCow ++;
31
- curCow ++;
32
+ //curCow++;
33
+ curCow = curCow + range + 1 ;
34
+ // curCow ++;
32
35
33
36
}
34
37
return cowsUsed ;
@@ -52,13 +55,13 @@ public static void main(String[] args) throws IOException{
52
55
int m = (l + r ) / 2 ;
53
56
int t = launchSim (m );
54
57
if (t < K ) {
55
- r = m - 1 ;
58
+ r = m ;
56
59
}else if (K == t ) {
57
- //System.out.println("Got it");
58
- r = m - 1 ;
60
+ // System.out.println("Got it");
61
+ r = m ;
59
62
//break;
60
63
}else {
61
- l = m + 1 ;
64
+ l = m ;
62
65
}
63
66
}
64
67
You can’t perform that action at this time.
0 commit comments