結果
問題 | No.1012 荷物収集 |
ユーザー | htensai |
提出日時 | 2020-03-24 14:38:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,536 ms / 2,000 ms |
コード長 | 2,176 bytes |
コンパイル時間 | 2,462 ms |
コンパイル使用メモリ | 78,948 KB |
実行使用メモリ | 78,928 KB |
最終ジャッジ日時 | 2024-12-31 15:00:06 |
合計ジャッジ時間 | 45,663 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
48,072 KB |
testcase_01 | AC | 137 ms
41,460 KB |
testcase_02 | AC | 136 ms
41,408 KB |
testcase_03 | AC | 134 ms
41,568 KB |
testcase_04 | AC | 1,164 ms
71,560 KB |
testcase_05 | AC | 1,341 ms
70,472 KB |
testcase_06 | AC | 1,270 ms
71,188 KB |
testcase_07 | AC | 1,239 ms
70,500 KB |
testcase_08 | AC | 1,246 ms
71,656 KB |
testcase_09 | AC | 1,336 ms
70,252 KB |
testcase_10 | AC | 1,261 ms
70,556 KB |
testcase_11 | AC | 1,300 ms
71,412 KB |
testcase_12 | AC | 1,324 ms
71,708 KB |
testcase_13 | AC | 1,252 ms
72,204 KB |
testcase_14 | AC | 207 ms
48,472 KB |
testcase_15 | AC | 225 ms
42,964 KB |
testcase_16 | AC | 220 ms
42,496 KB |
testcase_17 | AC | 235 ms
42,996 KB |
testcase_18 | AC | 221 ms
54,452 KB |
testcase_19 | AC | 218 ms
54,272 KB |
testcase_20 | AC | 218 ms
54,356 KB |
testcase_21 | AC | 213 ms
54,852 KB |
testcase_22 | AC | 212 ms
54,504 KB |
testcase_23 | AC | 204 ms
54,504 KB |
testcase_24 | AC | 1,205 ms
75,816 KB |
testcase_25 | AC | 1,363 ms
78,928 KB |
testcase_26 | AC | 1,092 ms
62,352 KB |
testcase_27 | AC | 586 ms
49,508 KB |
testcase_28 | AC | 1,473 ms
69,172 KB |
testcase_29 | AC | 1,131 ms
62,204 KB |
testcase_30 | AC | 1,536 ms
69,320 KB |
testcase_31 | AC | 765 ms
53,176 KB |
testcase_32 | AC | 738 ms
52,268 KB |
testcase_33 | AC | 933 ms
56,448 KB |
testcase_34 | AC | 926 ms
57,048 KB |
testcase_35 | AC | 1,310 ms
64,656 KB |
testcase_36 | AC | 919 ms
55,684 KB |
testcase_37 | AC | 1,109 ms
63,412 KB |
testcase_38 | AC | 1,248 ms
66,344 KB |
testcase_39 | AC | 868 ms
53,112 KB |
testcase_40 | AC | 884 ms
53,484 KB |
testcase_41 | AC | 1,445 ms
71,524 KB |
testcase_42 | AC | 855 ms
56,896 KB |
testcase_43 | AC | 1,073 ms
64,408 KB |
testcase_44 | AC | 142 ms
41,416 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int q = sc.nextInt(); Pack[] packs = new Pack[n + 2]; for (int i = 0; i < n; i++) { packs[i] = new Pack(sc.nextInt(), sc.nextInt()); } packs[n] = new Pack(0, 0); packs[n + 1] = new Pack(Integer.MAX_VALUE, 0); Arrays.sort(packs); long[] leftWeight = new long[n + 2]; long[] leftCosts = new long[n + 2]; leftWeight[0] = packs[0].weight; for (int i = 1; i < n + 2; i++) { leftWeight[i] = leftWeight[i - 1] + packs[i].weight; leftCosts[i] = leftCosts[i - 1] + (packs[i].point - packs[i - 1].point) * leftWeight[i - 1]; } long[] rightWeight = new long[n + 2]; long[] rightCosts = new long[n + 2]; rightWeight[n + 1] = packs[n + 1].weight; for (int i = n; i >= 0; i--) { rightWeight[i] = rightWeight[i + 1] + packs[i].weight; rightCosts[i] = rightCosts[i + 1] + (packs[i + 1].point - packs[i].point) * rightWeight[i + 1]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int x = sc.nextInt(); int left = 0; int right = n + 1; while (right - left > 1) { int m = (left + right) / 2; if (packs[m].point <= x) { left = m; } else { right = m; } } long ans = leftCosts[left] + leftWeight[left] * (x - packs[left].point) + rightCosts[right] + rightWeight[right] * (packs[right].point - x); sb.append(ans).append("\n"); } System.out.print(sb); } static class Pack implements Comparable<Pack> { int point; int weight; public Pack(int point, int weight) { this.point = point; this.weight = weight; } public int compareTo(Pack another) { return point - another.point; } } }