Skip to content

Commit 704db25

Browse files
committed
jol_1141_불쾌한날
1 parent b19c017 commit 704db25

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Gold/jol_1141_불쾌한날.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Stack;
5+
6+
public class jol_1141_불쾌한날 {
7+
static class Cow{
8+
int h,w;
9+
Cow(int h, int w){
10+
this.h=h;
11+
this.w=w;
12+
}
13+
}
14+
15+
public static void main(String[] args) throws IOException{
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
int N = Integer.parseInt(br.readLine());
18+
Cow[] Cows = new Cow[N];
19+
for(int i=0; i<N ;i++){
20+
Cows[i] = new Cow(Integer.parseInt(br.readLine()), 0);
21+
}
22+
23+
Stack<Cow> stack = new Stack<>();
24+
long sum=0;
25+
for(int i=N-1; i>=0; i--){
26+
27+
while(!stack.isEmpty() && stack.peek().h < Cows[i].h){
28+
Cows[i].w+=stack.peek().w+1;
29+
stack.pop();
30+
}
31+
sum+=Cows[i].w;
32+
stack.push(Cows[i]);
33+
}
34+
System.out.println(sum);
35+
}
36+
}

0 commit comments

Comments
 (0)