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

Commit 1d48bfa

Browse files
authored
Add files via upload
1 parent f5811af commit 1d48bfa

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

convention.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
import java.io.*;
3+
import java.util.*;
4+
public class convention {
5+
public static void endProgram(int answer) throws IOException{
6+
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("convention.out")));
7+
pw.println(answer);
8+
pw.close();
9+
System.exit(0);
10+
}
11+
public static void main(String[] args) throws IOException{
12+
BufferedReader f = new BufferedReader(new FileReader("convention1.in"));
13+
StringTokenizer st = new StringTokenizer(f.readLine());
14+
int N,M,C;
15+
N = Integer.parseInt(st.nextToken());
16+
M = Integer.parseInt(st.nextToken());
17+
C = Integer.parseInt(st.nextToken());
18+
st = new StringTokenizer(f.readLine());
19+
f.close();
20+
System.out.println(N+" "+M+" "+C);
21+
List<Integer> arrivTime = new ArrayList<>();
22+
for(int i = 0; i < N; i ++) {
23+
arrivTime.add(Integer.parseInt(st.nextToken()));
24+
}
25+
if(C == 1) {
26+
endProgram(N);
27+
}
28+
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;
46+
while(true) {
47+
// Pick Optimally?
48+
if(required > N - (answer*2)) {
49+
break;
50+
}
51+
PriorityElem p = options.remove(0);
52+
answer += 1;
53+
required += C-2;
54+
}
55+
System.out.println("");
56+
endProgram(answer);
57+
}
58+
59+
}
60+
61+
class Cow implements Comparator<Cow>{
62+
int id;
63+
int aTime;
64+
public Cow(int id, int aTime) {
65+
this.id = id;
66+
this.aTime = aTime;
67+
}
68+
@Override
69+
public int compare(Cow arg0, Cow arg1) {
70+
// TODO Auto-generated method stub
71+
return Integer.compare(arg0.aTime, arg1.aTime);
72+
}
73+
}
74+
class PriorityElem implements Comparator<PriorityElem>, Comparable<PriorityElem>{
75+
public int multiplier = 1;
76+
public int priority;
77+
public int item;
78+
public PriorityElem(int item, int priority) {
79+
this.item = item;
80+
this.priority = priority;
81+
}
82+
@Override
83+
public int compare(PriorityElem arg0, PriorityElem arg1) {
84+
// TODO Auto-generated method stub
85+
return Integer.compare(arg0.priority, arg1.priority);
86+
}
87+
@Override
88+
public int compareTo(PriorityElem arg0) {
89+
90+
return this.compare(this, arg0);
91+
}
92+
}

0 commit comments

Comments
 (0)