Skip to content

Commit 2f1e783

Browse files
authored
Merge pull request #314 from AlgorithmWithGod/ShinHeeEul
[20250417] BOJ / G2 / 너 봄에는 캡사이신이 맛있단다 / 신희을
2 parents fe4be4f + a2e7ddc commit 2f1e783

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class Main {
6+
7+
static int MOD = 1_000_000_007;
8+
9+
static StringBuilder sb = new StringBuilder();
10+
static String s;
11+
static long[] arr;
12+
static long[] max;
13+
static long[] min;
14+
static long ans = 0;
15+
static int N;
16+
public static void main(String[] args) throws Exception {
17+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
18+
19+
N = read();
20+
21+
// 슬라이딩 윈도우 처럼
22+
arr = new long[N];
23+
24+
for(int i = 0; i < N; i++) {
25+
arr[i] = read();
26+
}
27+
28+
// 정렬 하고?
29+
Arrays.sort(arr);
30+
31+
long[] pow2 = new long[N];
32+
pow2[0] = 1;
33+
for (int i = 1; i < N; i++) {
34+
pow2[i] = (pow2[i-1] * 2) % MOD;
35+
}
36+
37+
38+
39+
for(int i = arr.length - 1; i >= 0; i--) {
40+
ans = (ans + arr[i] * ((pow(2, i) - pow(2, N - i - 1) + MOD) % MOD) % MOD) % MOD;
41+
}
42+
43+
44+
System.out.println(ans);
45+
}
46+
47+
48+
public static long pow(long n, long r) {
49+
50+
n %= MOD;
51+
long result = 1L;
52+
while(r > 0) {
53+
if((r & 1) == 1) {
54+
result = (result * n) % MOD;
55+
}
56+
n = (n * n) % MOD;
57+
r >>= 1;
58+
}
59+
60+
return result % MOD;
61+
}
62+
63+
private static int read() throws Exception {
64+
int c;
65+
int n = 0;
66+
boolean negative = false;
67+
68+
while ((c = System.in.read()) <= 32) {
69+
if (c == -1) return -1;
70+
}
71+
72+
if (c == '-') {
73+
negative = true;
74+
c = System.in.read();
75+
}
76+
77+
do {
78+
n = n * 10 + (c - '0');
79+
c = System.in.read();
80+
} while (c > 32);
81+
82+
return negative ? -n : n;
83+
}
84+
85+
86+
}
87+
```

0 commit comments

Comments
 (0)