結果
問題 | No.1012 荷物収集 |
ユーザー | tenten |
提出日時 | 2022-08-30 15:07:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 707 ms / 2,000 ms |
コード長 | 2,677 bytes |
コンパイル時間 | 2,902 ms |
コンパイル使用メモリ | 78,532 KB |
実行使用メモリ | 58,084 KB |
最終ジャッジ日時 | 2024-04-25 00:22:24 |
合計ジャッジ時間 | 22,065 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
37,040 KB |
testcase_01 | AC | 52 ms
36,684 KB |
testcase_02 | AC | 51 ms
37,124 KB |
testcase_03 | AC | 51 ms
36,804 KB |
testcase_04 | AC | 426 ms
57,884 KB |
testcase_05 | AC | 442 ms
57,936 KB |
testcase_06 | AC | 412 ms
57,748 KB |
testcase_07 | AC | 438 ms
57,468 KB |
testcase_08 | AC | 452 ms
58,064 KB |
testcase_09 | AC | 466 ms
57,820 KB |
testcase_10 | AC | 440 ms
57,656 KB |
testcase_11 | AC | 458 ms
57,812 KB |
testcase_12 | AC | 437 ms
57,712 KB |
testcase_13 | AC | 453 ms
58,084 KB |
testcase_14 | AC | 58 ms
37,084 KB |
testcase_15 | AC | 69 ms
38,364 KB |
testcase_16 | AC | 57 ms
37,512 KB |
testcase_17 | AC | 76 ms
37,964 KB |
testcase_18 | AC | 63 ms
37,596 KB |
testcase_19 | AC | 58 ms
37,088 KB |
testcase_20 | AC | 57 ms
37,528 KB |
testcase_21 | AC | 62 ms
37,460 KB |
testcase_22 | AC | 60 ms
37,612 KB |
testcase_23 | AC | 59 ms
37,088 KB |
testcase_24 | AC | 511 ms
55,092 KB |
testcase_25 | AC | 627 ms
56,576 KB |
testcase_26 | AC | 403 ms
49,936 KB |
testcase_27 | AC | 214 ms
44,812 KB |
testcase_28 | AC | 592 ms
55,484 KB |
testcase_29 | AC | 417 ms
50,268 KB |
testcase_30 | AC | 614 ms
56,816 KB |
testcase_31 | AC | 388 ms
52,096 KB |
testcase_32 | AC | 339 ms
49,996 KB |
testcase_33 | AC | 445 ms
54,148 KB |
testcase_34 | AC | 462 ms
54,388 KB |
testcase_35 | AC | 562 ms
53,720 KB |
testcase_36 | AC | 440 ms
55,324 KB |
testcase_37 | AC | 410 ms
49,980 KB |
testcase_38 | AC | 530 ms
53,992 KB |
testcase_39 | AC | 330 ms
48,816 KB |
testcase_40 | AC | 378 ms
50,504 KB |
testcase_41 | AC | 707 ms
55,804 KB |
testcase_42 | AC | 420 ms
52,012 KB |
testcase_43 | AC | 494 ms
51,372 KB |
testcase_44 | AC | 51 ms
36,708 KB |
ソースコード
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(); } }