結果

問題 No.1012 荷物収集
ユーザー tentententen
提出日時 2021-08-06 15:06:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,132 bytes
コンパイル時間 2,485 ms
コンパイル使用メモリ 78,548 KB
実行使用メモリ 71,472 KB
最終ジャッジ日時 2023-10-17 01:54:25
合計ジャッジ時間 23,776 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,500 KB
testcase_01 AC 52 ms
53,504 KB
testcase_02 AC 53 ms
53,488 KB
testcase_03 AC 52 ms
53,508 KB
testcase_04 AC 427 ms
68,616 KB
testcase_05 AC 432 ms
69,228 KB
testcase_06 AC 441 ms
69,240 KB
testcase_07 AC 432 ms
68,440 KB
testcase_08 AC 448 ms
68,316 KB
testcase_09 AC 447 ms
69,156 KB
testcase_10 AC 408 ms
66,784 KB
testcase_11 AC 405 ms
67,412 KB
testcase_12 AC 443 ms
69,212 KB
testcase_13 AC 404 ms
66,748 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 53 ms
53,444 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();
        Pack[] packs = new Pack[n];
        long ans = 0;
        int right = 0;
        for (int i = 0; i < n; i++) {
            packs[i] = new Pack(sc.nextInt(), sc.nextInt());
            ans += (long)packs[i].weight * packs[i].position;
            right += packs[i].weight;
        }
        Arrays.sort(packs);
        int left = 0;
        int prev = 0;
        int idx = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            ans += (long)left * (x - prev);
            while (idx < n && packs[idx].position <= x) {
                ans += ((long)x + prev - packs[idx].position * 2) * packs[idx].weight;
                left += packs[idx].weight;
                right -= packs[idx].weight;
                idx++;
            }
            ans -= (long)right * (x - prev);
            sb.append(ans).append("\n");
            prev = x;
        }
        System.out.print(sb);
    }
    
    static class Pack implements Comparable<Pack> {
        int position;
        int weight;
        
        public Pack(int position, int weight) {
            this.position = position;
            this.weight = weight;
        }
        
        public int compareTo(Pack another) {
            return position - another.position;
        }
    }
    

}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0