File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ //https://www.acmicpc.net/problem/28324
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+ import java .util .StringTokenizer ;
7+
8+ public class BOJ_S4_28324_스케이트연습 {
9+
10+ public static void main (String [] args ) throws IOException {
11+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
12+
13+ int N = Integer .parseInt (br .readLine ());
14+ int [] nums = new int [N ];
15+
16+ StringTokenizer st = new StringTokenizer (br .readLine ());
17+ for (int i = 0 ; i < N ; i ++) {
18+ nums [i ] = Integer .parseInt (st .nextToken ());
19+ }
20+
21+ long ans = 0 ;
22+ int expectNum = 1 ;
23+
24+ for (int i = N -1 ; i >= 0 ; i --) {
25+ if (nums [i ] >= expectNum ) {
26+ ans += expectNum ++;
27+ } else {
28+ ans += nums [i ];
29+ expectNum = nums [i ]+1 ;
30+ }
31+ }
32+
33+ System .out .println (ans );
34+
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments