-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathNeerc.java
More file actions
43 lines (39 loc) · 1.37 KB
/
Copy pathNeerc.java
File metadata and controls
43 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package neerc;
import java.util.*;
import java.io.*;
public class Neerc {
private static ArrayList<Integer> team = new ArrayList<>();
private static ArrayList<Integer> startData = new ArrayList<>();
private static void getData() throws IOException{
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
int numberLine = 0;
while (sc.hasNextLine()){
numberLine++;
String str = sc.nextLine();
StringTokenizer st = new StringTokenizer(str, " ");
while (st.hasMoreTokens()){
if(numberLine == 2){
team.add(Integer.valueOf(st.nextToken())); // Количество участников от каждого института
}else{
startData.add(Integer.valueOf(st.nextToken()));
}
}
}
}
public static void main(String[] argv) throws IOException {
getData();
int roomCount = startData.get(1);
int contestant = 0;
for (Integer aTeam : team) {
if (roomCount >= aTeam) {
contestant += aTeam;
} else {
contestant += roomCount;
}
}
PrintWriter pw = new PrintWriter(new File("output.txt"));
pw.print(String.valueOf(contestant));
pw.close();
}
}