結果

問題 No.1012 荷物収集
ユーザー tentententen
提出日時 2023-04-11 08:23:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 826 ms / 2,000 ms
コード長 3,131 bytes
コンパイル時間 3,361 ms
コンパイル使用メモリ 88,280 KB
実行使用メモリ 58,916 KB
最終ジャッジ日時 2024-10-06 23:39:07
合計ジャッジ時間 23,718 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
37,988 KB
testcase_01 AC 68 ms
37,708 KB
testcase_02 AC 70 ms
37,980 KB
testcase_03 AC 68 ms
37,964 KB
testcase_04 AC 501 ms
57,180 KB
testcase_05 AC 496 ms
57,180 KB
testcase_06 AC 524 ms
57,072 KB
testcase_07 AC 491 ms
57,052 KB
testcase_08 AC 503 ms
56,904 KB
testcase_09 AC 497 ms
57,220 KB
testcase_10 AC 498 ms
56,924 KB
testcase_11 AC 487 ms
56,900 KB
testcase_12 AC 493 ms
56,940 KB
testcase_13 AC 514 ms
56,992 KB
testcase_14 AC 81 ms
38,056 KB
testcase_15 AC 97 ms
38,804 KB
testcase_16 AC 83 ms
38,156 KB
testcase_17 AC 92 ms
38,584 KB
testcase_18 AC 86 ms
38,136 KB
testcase_19 AC 83 ms
37,736 KB
testcase_20 AC 86 ms
38,372 KB
testcase_21 AC 84 ms
38,348 KB
testcase_22 AC 102 ms
38,180 KB
testcase_23 AC 82 ms
37,744 KB
testcase_24 AC 593 ms
57,020 KB
testcase_25 AC 684 ms
57,236 KB
testcase_26 AC 466 ms
50,556 KB
testcase_27 AC 250 ms
46,060 KB
testcase_28 AC 677 ms
58,916 KB
testcase_29 AC 459 ms
50,296 KB
testcase_30 AC 691 ms
58,100 KB
testcase_31 AC 445 ms
56,256 KB
testcase_32 AC 395 ms
51,516 KB
testcase_33 AC 503 ms
55,960 KB
testcase_34 AC 517 ms
56,504 KB
testcase_35 AC 642 ms
55,464 KB
testcase_36 AC 523 ms
57,512 KB
testcase_37 AC 460 ms
49,936 KB
testcase_38 AC 608 ms
55,504 KB
testcase_39 AC 393 ms
48,964 KB
testcase_40 AC 437 ms
52,176 KB
testcase_41 AC 826 ms
58,292 KB
testcase_42 AC 473 ms
53,860 KB
testcase_43 AC 590 ms
55,608 KB
testcase_44 AC 70 ms
37,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int q = sc.nextInt();
        Point[] points = new Point[n + q];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(0, sc.nextInt(), sc.nextInt());
        }
        for (int i = n; i < n + q; i++) {
            points[i] = new Point(i - n, sc.nextInt(), 0);
        }
        Arrays.sort(points);
        long[] ans = new long[q];
        long leftWeight = 0;
        long leftSum = 0;
        int leftPrev = 0;
        for (int i = 0; i < n + q; i++) {
            leftSum += (points[i].position - leftPrev) * leftWeight;
            leftWeight += points[i].weight;
            leftPrev = points[i].position;
            if (points[i].weight == 0) {
                ans[points[i].idx] += leftSum;
            }
        }
        long rightWeight = 0;
        long rightSum = 0;
        int rightPrev = 0;
        for (int i = n + q - 1; i >= 0; i--) {
            rightSum += (rightPrev - points[i].position) * rightWeight;
            rightWeight += points[i].weight;
            rightPrev = points[i].position;
            if (points[i].weight == 0) {
                ans[points[i].idx] += rightSum;
            }
        }
        System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new)));
    }
    
    static class Point implements Comparable<Point> {
        int idx;
        int position;
        int weight;
        
        public Point(int idx, int position, int weight) {
            this.idx = idx;
            this.position = position;
            this.weight = weight;
        }
        
        public int compareTo(Point another) {
            return position - another.position;
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0