Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 1f4c498

Browse files
authored
Nonworking new version
1 parent 1d48bfa commit 1f4c498

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

convention.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
import java.io.*;
33
import java.util.*;
44
public class convention {
5+
public static boolean check(int test,int M, int C, List<Integer> buses) {
6+
int busStart=buses.get(0);
7+
int busCount = 1;
8+
int cowCount = 0;
9+
for(int i = 0; i < buses.size(); i ++) {
10+
if(busCount > M) {
11+
return false;
12+
}
13+
int time = buses.get(i);
14+
if(time - busStart > test || cowCount == C) {
15+
busCount ++;
16+
busStart = time;
17+
cowCount = 0;
18+
}
19+
cowCount++;
20+
}
21+
return true;
22+
}
523
public static void endProgram(int answer) throws IOException{
624
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("convention.out")));
725
pw.println(answer);
@@ -22,38 +40,19 @@ public static void main(String[] args) throws IOException{
2240
for(int i = 0; i < N; i ++) {
2341
arrivTime.add(Integer.parseInt(st.nextToken()));
2442
}
25-
if(C == 1) {
26-
endProgram(N);
27-
}
2843
arrivTime.sort(null);
29-
List<PriorityElem> options = new ArrayList<>();
30-
int required = 0;
31-
for(int i = 0; i < N-C; i ++) {
32-
//System.out.println("Pos: "+(i+C)+" , "+i);
33-
//System.out.println("Dif: "+arrivTime.get(i+C)+" , "+arrivTime.get(i));
34-
int diff = arrivTime.get(i+C) - arrivTime.get(i);
35-
//System.out.println(diff);
36-
options.add(new PriorityElem(i,diff));
37-
// Pick diffs
38-
}
39-
//Collections.reverse(arrivTime);
40-
//System.out.println(arrivTime);
41-
options.sort(null);
42-
for(PriorityElem pe: options) {
43-
//System.out.println(pe.item + " "+pe.priority);
44-
}
45-
int answer = 0;
44+
// 123456789
45+
int max = 1000000000;
46+
int min = 0;
4647
while(true) {
47-
// Pick Optimally?
48-
if(required > N - (answer*2)) {
49-
break;
48+
int mid = (int) Math.floor((min + max)/2);
49+
if(check(mid,M,C,arrivTime)) {
50+
max = mid;
51+
}else {
52+
min = mid;
5053
}
51-
PriorityElem p = options.remove(0);
52-
answer += 1;
53-
required += C-2;
54+
System.out.println(min+" "+mid+" "+max);
5455
}
55-
System.out.println("");
56-
endProgram(answer);
5756
}
5857

5958
}

0 commit comments

Comments
 (0)