結果
問題 | No.1012 荷物収集 |
ユーザー | tenten |
提出日時 | 2021-08-06 15:10:26 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 708 ms / 2,000 ms |
コード長 | 2,427 bytes |
コンパイル時間 | 2,530 ms |
コンパイル使用メモリ | 78,644 KB |
実行使用メモリ | 58,572 KB |
最終ジャッジ日時 | 2024-09-17 00:29:18 |
合計ジャッジ時間 | 21,612 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
36,792 KB |
testcase_01 | AC | 55 ms
36,976 KB |
testcase_02 | AC | 54 ms
36,900 KB |
testcase_03 | AC | 55 ms
37,220 KB |
testcase_04 | AC | 473 ms
58,500 KB |
testcase_05 | AC | 467 ms
58,476 KB |
testcase_06 | AC | 480 ms
58,524 KB |
testcase_07 | AC | 448 ms
58,396 KB |
testcase_08 | AC | 462 ms
57,648 KB |
testcase_09 | AC | 465 ms
57,656 KB |
testcase_10 | AC | 470 ms
57,284 KB |
testcase_11 | AC | 459 ms
58,572 KB |
testcase_12 | AC | 464 ms
58,464 KB |
testcase_13 | AC | 479 ms
58,540 KB |
testcase_14 | AC | 69 ms
37,356 KB |
testcase_15 | AC | 87 ms
38,552 KB |
testcase_16 | AC | 80 ms
37,404 KB |
testcase_17 | AC | 78 ms
38,412 KB |
testcase_18 | AC | 76 ms
37,852 KB |
testcase_19 | AC | 65 ms
37,232 KB |
testcase_20 | AC | 80 ms
37,704 KB |
testcase_21 | AC | 77 ms
37,904 KB |
testcase_22 | AC | 82 ms
37,660 KB |
testcase_23 | AC | 66 ms
37,624 KB |
testcase_24 | AC | 536 ms
56,648 KB |
testcase_25 | AC | 668 ms
56,932 KB |
testcase_26 | AC | 432 ms
50,460 KB |
testcase_27 | AC | 229 ms
44,136 KB |
testcase_28 | AC | 615 ms
54,032 KB |
testcase_29 | AC | 452 ms
51,320 KB |
testcase_30 | AC | 644 ms
56,840 KB |
testcase_31 | AC | 402 ms
50,484 KB |
testcase_32 | AC | 340 ms
47,560 KB |
testcase_33 | AC | 436 ms
55,060 KB |
testcase_34 | AC | 460 ms
55,792 KB |
testcase_35 | AC | 558 ms
52,428 KB |
testcase_36 | AC | 469 ms
53,844 KB |
testcase_37 | AC | 434 ms
48,196 KB |
testcase_38 | AC | 543 ms
51,916 KB |
testcase_39 | AC | 339 ms
49,344 KB |
testcase_40 | AC | 370 ms
48,920 KB |
testcase_41 | AC | 708 ms
56,948 KB |
testcase_42 | AC | 403 ms
51,256 KB |
testcase_43 | AC | 507 ms
51,556 KB |
testcase_44 | AC | 57 ms
37,100 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(); 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); Pack[] places = new Pack[q]; for (int i = 0; i < q; i++) { places[i] = new Pack(sc.nextInt(), i); } Arrays.sort(places); int left = 0; int prev = 0; int idx = 0; long[] results = new long[q]; for (int i = 0; i < q; i++) { int x = places[i].position; 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); results[places[i].weight] = ans; prev = x; } StringBuilder sb = new StringBuilder(); for (long x : results) { sb.append(x).append("\n"); } 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(); } }