|
| 1 | +```java |
| 2 | +import java.io.BufferedReader; |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStreamReader; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.HashSet; |
| 10 | +import java.util.LinkedList; |
| 11 | +import java.util.PriorityQueue; |
| 12 | +import java.util.Queue; |
| 13 | +import java.util.StringTokenizer; |
| 14 | + |
| 15 | +public class Main { |
| 16 | + |
| 17 | + static int height, width,ans; |
| 18 | + static boolean[][] arr; |
| 19 | + |
| 20 | + |
| 21 | + public static void main(String[] args) throws IOException { |
| 22 | + init(); |
| 23 | + process(); |
| 24 | + print(); |
| 25 | + |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + private static void init() throws IOException{ |
| 30 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 31 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 32 | + |
| 33 | + height = Integer.parseInt(st.nextToken()); |
| 34 | + width = Integer.parseInt(st.nextToken()); |
| 35 | + |
| 36 | + arr = new boolean[height][width]; |
| 37 | + ans = 0; |
| 38 | + |
| 39 | + st = new StringTokenizer(br.readLine()); |
| 40 | + for (int i = 0; i < width; i++) { |
| 41 | + int h = Integer.parseInt(st.nextToken()); |
| 42 | + for (int j = 0; j < j; j++) { |
| 43 | + arr[j][i]= true; |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + private static void process() throws IOException { |
| 52 | + for (int i = 0; i < height; i++) { |
| 53 | + ArrayList<Integer> idxes = new ArrayList<>(); |
| 54 | + for (int j = 0; j < width; j++) { |
| 55 | + if(arr[i][j]) idxes.add(j); |
| 56 | + } |
| 57 | + |
| 58 | + if (idxes.size() < 2) return; |
| 59 | + |
| 60 | + int pre = idxes.get(0); |
| 61 | + |
| 62 | + for(int j = 1; j < idxes.size(); j++) { |
| 63 | + int cur = idxes.get(i); |
| 64 | + ans += cur - pre; |
| 65 | + pre = cur; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + private static void print() { |
| 73 | + System.out.print(ans); |
| 74 | + } |
| 75 | + |
| 76 | +} |
| 77 | +``` |
0 commit comments