一个长度为M的正整数数组A,表示从左向右的地形高度。测试一种加农炮,炮弹平行于地面从左向右飞行,高度为H,如果某处地形的高度大于等于炮弹飞行的高度H(A[i] >= H),炮弹会被挡住并落在i - 1处,则A[i - 1] + 1。如果H <= A[0],则这个炮弹无效,如果H > 所有的A[i],这个炮弹也无效。现在给定N个整数的数组B代表炮弹高度,计算出最后地形的样子。
例如:地形高度A = {1, 2, 0, 4, 3, 2, 1, 5, 7}, 炮弹高度B = {2, 8, 0, 7, 6, 5, 3, 4, 5, 6, 5},最终得到的地形高度为:{2, 2, 2, 4, 3, 3, 5, 6, 7}。
模拟题,刚开始的直接模拟整个的过程,但是直接超市,第一次写的代码
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner cin = new Scanner(System.in);
// BufferedReader reader = new BufferedReader(new
// InputStreamReader(System.in), 1 << 16);
// BufferedWriter writer = new BufferedWriter(new
// OutputStreamWriter(System.out), 1 << 16);
//
// String s = null;
// String[] ss = null;
// s = reader.readLine();
// ss = s.split(" ");
int m = cin.nextInt();
int n = cin.nextInt();
int[] a = new int[m];
int[] b = new int[n];
// HashMap<Integer, PriorityQueue<Integer>> site = new
// HashMap<>();//对应数值到位置的映射函数
// PriorityQueue<Integer> minQ = new PriorityQueue<>();
// PriorityQueue<Integer> maxQ = new PriorityQueue<>(new
// Comparator<Integer>() {
//
// @Override
// public int compare(Integer o1, Integer o2) {
// return o2 - o1;
// }
// });
ArrayList<Integer> left = new ArrayList<>();
ArrayList<Integer> right = new ArrayList<>();
// ArrayList<PriorityQueue<Integer>>
int pre = 0, next = 0;
a[0] = cin.nextInt();
for (int i = 1; i < a.length; ++i) {
a[i] = cin.nextInt();
if (a[i] > a[i