結果

問題 No.1012 荷物収集
ユーザー ks2mks2m
提出日時 2020-03-20 22:34:05
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 2,753 ms
コンパイル使用メモリ 90,936 KB
実行使用メモリ 63,140 KB
最終ジャッジ日時 2024-05-08 22:51:50
合計ジャッジ時間 24,687 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
37,104 KB
testcase_01 AC 58 ms
37,516 KB
testcase_02 AC 58 ms
37,660 KB
testcase_03 AC 57 ms
37,500 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 74 ms
38,072 KB
testcase_15 AC 100 ms
38,688 KB
testcase_16 AC 87 ms
38,152 KB
testcase_17 AC 92 ms
38,200 KB
testcase_18 AC 87 ms
38,500 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 85 ms
38,376 KB
testcase_22 AC 89 ms
38,076 KB
testcase_23 AC 80 ms
38,364 KB
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 58 ms
37,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		Obj[] arr = new Obj[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.x = Integer.parseInt(sa[0]);
			o.w = Integer.parseInt(sa[1]);
			arr[i] = o;
		}
		sa = br.readLine().split(" ");
		Query[] qu = new Query[q];
		for (int i = 0; i < q; i++) {
			Query o = new Query();
			o.i = i;
			o.x = Integer.parseInt(sa[i]);
			qu[i] = o;
		}
		br.close();

		Arrays.parallelSort(arr, (o1, o2) -> o1.x - o2.x);
		Arrays.parallelSort(qu, (o1, o2) -> o1.x - o2.x);

		long right = 0;
		for (int i = 0; i < n; i++) {
			right += arr[i].w;
		}

		int pre = 0;
		int idx = 0;
		long left = 0;
		for (int i = 0; i < q; i++) {
			long val = left * (qu[i].x - pre);
			if (i > 0) {
				val += qu[i - 1].ans;
			}
			while (idx < n) {
				Obj o = arr[idx];
				if (o.x <= qu[i].x) {
					val += (qu[i].x - o.x) * o.w;
					if (i > 0) {
						val -= (o.x - qu[i - 1].x) * o.w;
					}
					left += o.w;
					right -= o.w;
					idx++;
				} else {
					break;
				}
			}
			if (i == 0) {
				for (int j = idx; j < n; j++) {
					val += (arr[j].x - qu[i].x) * arr[j].w;
				}
			} else {
				val -= right * (qu[i].x - pre);
			}
			qu[i].ans = val;
			pre = qu[i].x;
		}

		Arrays.parallelSort(qu, (o1, o2) -> o1.i - o2.i);
		PrintWriter pw = new PrintWriter(System.out);
		for (Query o : qu) {
			pw.println(o.ans);
		}
		pw.flush();
	}

	static class Obj {
		int x, w;
	}

	static class Query {
		int i, x;
		long ans;
	}
}
0