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

Commit 118c82a

Browse files
authored
Add files via upload
1 parent fff71eb commit 118c82a

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

Java/bin/angry.class

-17 Bytes
Binary file not shown.

Java/src/angry.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,51 @@
66
*/
77
public class angry {
88
static List<Integer> field = new ArrayList<Integer>();
9-
//public List<Integer> launchSim(int pos){
10-
//
11-
//}
9+
public static int N;
10+
public static int launchSim(int power){
11+
int cowsUsed = 0;
12+
int curCow = 0;
13+
while(curCow < N) {
14+
int pos = field.get(curCow);
15+
curCow++;
16+
for(int i = pos; i < N; i ++) {
17+
if(pos ) {
18+
curCow++;
19+
}
20+
}
21+
}
22+
return cowsUsed;
23+
}
1224
public static void main(String[] args) throws IOException{
1325
BufferedReader f = new BufferedReader(new FileReader("angry.in"));
1426
StringTokenizer st = new StringTokenizer(f.readLine());
15-
int N = Integer.parseInt(st.nextToken()); // Number of haybales
27+
N = Integer.parseInt(st.nextToken());
1628
int K = Integer.parseInt(st.nextToken()); // Number of cows
17-
List<Integer> costs = new ArrayList<Integer>(N - 1);
29+
//List<Integer> costs = new ArrayList<Integer>(N - 1);
1830
for(int i = 0; i < N; i ++) {
1931
field.add(Integer.parseInt(f.readLine()));
2032
}
2133
f.close();
2234
field.sort(null);
23-
for(int i = 0; i < (N-1); i ++) {
24-
costs.add(field.get(i+1) - field.get(i));
25-
}
35+
int answer = -1;
36+
int l = 0;
37+
int r = N;
38+
while (r - l > 1) {
39+
int m = (l + r) / 2;
40+
if (launchSim(m) < K) {
41+
r = m;
42+
} else {
43+
l = m;
44+
}
45+
}
46+
2647
System.out.println(field);
27-
System.out.println(costs);
48+
//System.out.println(costs);
49+
2850
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("angry.out")));
29-
pw.println(Collections.max(costs));
51+
pw.println(answer);
3052
pw.close();
3153
//System.out.println("");
32-
for(int i = 0 ; i < N; i ++) {
33-
34-
}
3554
}
3655

3756
}

0 commit comments

Comments
 (0)