编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3629 #1011. 小田的存钱罐 Compile Error 0 0 ms 0 K Java / 2.1 K caijiuduolian 2023-11-25 15:59:31
显示原始代码
import java.util.*;

public class zjj {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int num = scan.nextInt();
        int[] arr = new int[num];

        int[] result = new int[num];
        int k = 0;
        int o = 0;
        scan.nextLine();
        Map<Integer, Integer> remove = new HashMap<>();
        Map<Integer, Integer> memo = new HashMap<>();
        while (num != 0) {
            int next = scan.nextInt();
            if (next == 1) {
                int a = scan.nextInt();
                scan.nextLine();
                arr[k] = a;
                k++;
                memo.put(a, memo.getOrDefault(a, 0) + 1);
            } else if (next == 2) {
                int x = scan.nextInt();
                int c = scan.nextInt();
                scan.nextLine();
                int have = memo.get(x);
                if (c > have) {
                    memo.put(x, 0);
                    remove.put(x, 1);
                }
                memo.put(x, have - c);
            } else {
                scan.nextLine();
                int max = -10;
                int min = 100000;
                for (int i = 0; i < arr.length; i++) {
                    if (remove.containsKey(arr[i])) {
                        continue;
                    }
                    if (arr[i] == 0) {
                        continue;
                    }
                    if (arr[i] > max) {
                        max = arr[i];
                    }
                }
                for (int i = 0; i < arr.length; i++) {
                    if (remove.containsKey(arr[i])) {
                        continue;
                    }
                    if (arr[i] == 0) {
                        continue;
                    }
                    if (arr[i] < min) {
                        min = arr[i];
                    }
                }
                result[o] = max - min;
                o++;
            }
            num--;
        }
        for (int q = 0; q < result.length; q++) {
            if (result[q] == 0) {
                continue;
            }
            System.out.println(result[q]);
        }
    }
}

编译信息

A TimeLimitExceeded encountered while compiling your code.