File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments