Skip to content

Commit 1f556ea

Browse files
committed
[D2] Title: 백만 장자 프로젝트
D2, Time: 455 ms, Memory: 137,812 KB -BaekjoonHub
1 parent 0e8ad17 commit 1f556ea

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

‎SWEA/D2/1859. 백만 장자 프로젝트 D2/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
### 성능 요약
88

9-
메모리: 143,564 KB, 시간: 568 ms, 코드길이: 1,087 Bytes
9+
메모리: 137,812 KB, 시간: 455 ms, 코드길이: 921 Bytes
1010

1111
### 제출 일자
1212

13-
2026-05-21 22:59
13+
2026-05-21 23:02
1414

1515

1616

‎SWEA/D2/1859. 백만 장자 프로젝트 D2/백만 장자 프로젝트 D2.java‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ public static void main(String args[]) throws Exception {
1818

1919
// 뒤에서부터 오면서 최대값 기록, 갱신 시 지금까지 온 날짜만큼 팔기. -> 최대 2백만
2020
long ans = 0;
21-
int maxIndex = n - 1;
21+
int max = ary[n - 1];
2222
for(int i = n - 1; i >= 0; i--) {
23-
if (ary[maxIndex] < ary[i]) {
24-
for(int j = i + 1; j < maxIndex; j++) {
25-
ans += (long) ary[maxIndex] - ary[j];
26-
}
27-
maxIndex = i;
28-
} else if (i == 0) {
29-
for(int j = i; j < maxIndex; j++) {
30-
ans += (long) ary[maxIndex] - ary[j];
31-
}
23+
if (max > ary[i]) {
24+
ans += max - ary[i];
25+
} else if (max < ary[i]) {
26+
max = ary[i];
3227
}
3328
}
3429

0 commit comments

Comments
 (0)