Skip to content

Commit 7ab81e0

Browse files
authored
Merge pull request #290 from AlgorithmWithGod/khj20006
[20250327] BOJ / G3 / Fix Wiring / 권혁준
2 parents a866778 + f24ecee commit 7ab81e0

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st = new StringTokenizer("");
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static String nextToken() throws Exception {
15+
while(!st.hasMoreTokens()) nextLine();
16+
return st.nextToken();
17+
}
18+
static int nextInt() throws Exception { return Integer.parseInt(nextToken()); }
19+
static long nextLong() throws Exception { return Long.parseLong(nextToken()); }
20+
static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
21+
static void bwEnd() throws Exception {bw.flush();bw.close();}
22+
23+
// Additional field
24+
25+
static int N;
26+
static long[] A;
27+
28+
public static void main(String[] args) throws Exception {
29+
30+
ready();
31+
solve();
32+
33+
bwEnd();
34+
35+
}
36+
37+
static void ready() throws Exception{
38+
39+
N = nextInt();
40+
A = new long[N*(N-1)/2];
41+
for(int i=0;i<A.length;i++) A[i] = nextLong();
42+
43+
}
44+
45+
static void solve() throws Exception{
46+
47+
Arrays.sort(A);
48+
long min = 0, max = 0;
49+
int cntMin = 0, limitMax = 0, passMax = 0;
50+
for(int i=0;i<A.length;i++) {
51+
if(cntMin < N-1) {
52+
cntMin++;
53+
min += A[i];
54+
}
55+
if(passMax == limitMax) {
56+
passMax = 1;
57+
limitMax++;
58+
max += A[i];
59+
}
60+
else passMax++;
61+
}
62+
bw.write(min + " " + max);
63+
64+
}
65+
66+
}
67+
68+
```

0 commit comments

Comments
 (0)