結果
問題 | No.370 道路の掃除 |
ユーザー | Grenache |
提出日時 | 2016-07-02 13:14:49 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 2,144 bytes |
コンパイル時間 | 3,481 ms |
コンパイル使用メモリ | 79,476 KB |
実行使用メモリ | 39,108 KB |
最終ジャッジ日時 | 2024-04-22 17:51:19 |
合計ジャッジ時間 | 6,481 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
37,156 KB |
testcase_01 | AC | 49 ms
37,092 KB |
testcase_02 | AC | 51 ms
36,920 KB |
testcase_03 | AC | 51 ms
36,944 KB |
testcase_04 | AC | 52 ms
36,912 KB |
testcase_05 | AC | 50 ms
37,268 KB |
testcase_06 | AC | 50 ms
36,824 KB |
testcase_07 | AC | 50 ms
37,092 KB |
testcase_08 | AC | 50 ms
37,288 KB |
testcase_09 | AC | 50 ms
37,192 KB |
testcase_10 | AC | 53 ms
37,308 KB |
testcase_11 | AC | 52 ms
36,944 KB |
testcase_12 | AC | 53 ms
37,152 KB |
testcase_13 | AC | 52 ms
37,216 KB |
testcase_14 | AC | 54 ms
36,780 KB |
testcase_15 | AC | 53 ms
37,212 KB |
testcase_16 | AC | 53 ms
37,100 KB |
testcase_17 | AC | 52 ms
37,120 KB |
testcase_18 | AC | 52 ms
37,044 KB |
testcase_19 | AC | 54 ms
36,804 KB |
testcase_20 | AC | 77 ms
39,048 KB |
testcase_21 | AC | 77 ms
38,500 KB |
testcase_22 | AC | 61 ms
37,356 KB |
testcase_23 | AC | 79 ms
38,704 KB |
testcase_24 | AC | 59 ms
37,236 KB |
testcase_25 | AC | 74 ms
37,720 KB |
testcase_26 | AC | 83 ms
38,820 KB |
testcase_27 | AC | 70 ms
37,800 KB |
testcase_28 | AC | 65 ms
37,668 KB |
testcase_29 | AC | 77 ms
38,692 KB |
testcase_30 | AC | 85 ms
39,108 KB |
testcase_31 | AC | 82 ms
38,700 KB |
testcase_32 | AC | 74 ms
38,560 KB |
testcase_33 | AC | 77 ms
38,328 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder370 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int m = sc.nextInt(); List<Integer> pp = new ArrayList<>(); List<Integer> mm = new ArrayList<>(); pp.add(0); mm.add(0); int zz = 0; for (int i = 0; i < m; i++) { int d = sc.nextInt(); if (d > 0) { pp.add(d); } else if (d < 0) { mm.add(-d); } else { zz++; } } Collections.sort(pp); Collections.sort(mm); int min = Integer.MAX_VALUE; for (int i = 0; i < pp.size(); i++) { for (int j = 0; j < mm.size(); j++) { int tmp = zz; if (tmp + i + j >= n) { min = Math.min(min, pp.get(i) + 2 * mm.get(j)); min = Math.min(min, 2 * pp.get(i) + mm.get(j)); } } } pr.println(min); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }