結果

問題 No.1012 荷物収集
ユーザー tentententen
提出日時 2022-08-30 15:07:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 694 ms / 2,000 ms
コード長 2,677 bytes
コンパイル時間 3,189 ms
コンパイル使用メモリ 77,968 KB
実行使用メモリ 58,192 KB
最終ジャッジ日時 2024-11-07 09:46:24
合計ジャッジ時間 23,472 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,188 KB
testcase_01 AC 54 ms
37,028 KB
testcase_02 AC 54 ms
36,992 KB
testcase_03 AC 53 ms
37,188 KB
testcase_04 AC 450 ms
58,020 KB
testcase_05 AC 462 ms
58,192 KB
testcase_06 AC 466 ms
57,676 KB
testcase_07 AC 456 ms
57,796 KB
testcase_08 AC 476 ms
57,640 KB
testcase_09 AC 450 ms
57,768 KB
testcase_10 AC 482 ms
57,504 KB
testcase_11 AC 453 ms
57,952 KB
testcase_12 AC 455 ms
57,672 KB
testcase_13 AC 465 ms
57,644 KB
testcase_14 AC 64 ms
37,144 KB
testcase_15 AC 88 ms
38,548 KB
testcase_16 AC 68 ms
37,488 KB
testcase_17 AC 78 ms
38,172 KB
testcase_18 AC 80 ms
37,744 KB
testcase_19 AC 62 ms
37,184 KB
testcase_20 AC 64 ms
37,588 KB
testcase_21 AC 67 ms
37,300 KB
testcase_22 AC 67 ms
37,540 KB
testcase_23 AC 61 ms
36,788 KB
testcase_24 AC 554 ms
55,528 KB
testcase_25 AC 689 ms
57,048 KB
testcase_26 AC 426 ms
49,584 KB
testcase_27 AC 226 ms
44,964 KB
testcase_28 AC 615 ms
55,288 KB
testcase_29 AC 435 ms
50,220 KB
testcase_30 AC 659 ms
56,512 KB
testcase_31 AC 406 ms
51,832 KB
testcase_32 AC 353 ms
49,504 KB
testcase_33 AC 438 ms
54,200 KB
testcase_34 AC 475 ms
54,160 KB
testcase_35 AC 607 ms
53,752 KB
testcase_36 AC 446 ms
55,544 KB
testcase_37 AC 421 ms
49,988 KB
testcase_38 AC 581 ms
53,452 KB
testcase_39 AC 350 ms
48,960 KB
testcase_40 AC 376 ms
50,640 KB
testcase_41 AC 694 ms
55,660 KB
testcase_42 AC 443 ms
51,312 KB
testcase_43 AC 520 ms
51,732 KB
testcase_44 AC 54 ms
36,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 + 2];
        for (int i = 1; i <= n; i++) {
            points[i] = new Point(sc.nextInt(), sc.nextInt(), true);
        }
        for (int i = 0; i < q; i++) {
            points[i + n + 1] = new Point(sc.nextInt(), i, false);
        }
        points[0] = new Point(0, 0, true);
        points[n + q + 1] = new Point(Integer.MAX_VALUE, 0, true);
        Arrays.sort(points);
        long[] ans = new long[q];
        long total = 0;
        long weight = 0;
        for (int i = 1; i <= n + q; i++) {
            total += weight * (points[i].position - points[i - 1].position);
            if (points[i].isThing) {
                weight += points[i].value;
            } else {
                ans[points[i].value] += total;
            }
        }
        total = 0;
        weight = 0;
        for (int i = n + q; i >= 1; i--) {
            total += weight * (points[i + 1].position - points[i].position);
            if (points[i].isThing) {
                weight += points[i].value;
            } else {
                ans[points[i].value] += total;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (long x : ans) {
            sb.append(x).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Point implements Comparable<Point> {
        int position;
        int value;
        boolean isThing;
        
        public Point(int position, int value, boolean isThing) {
            this.position = position;
            this.value = value;
            this.isThing = isThing;
        }
        
        public int compareTo(Point another) {
            return position - another.position;
        }
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0