結果
問題 | No.370 道路の掃除 |
ユーザー | Grenache |
提出日時 | 2016-05-22 12:41:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 2,144 bytes |
コンパイル時間 | 3,777 ms |
コンパイル使用メモリ | 79,856 KB |
実行使用メモリ | 52,152 KB |
最終ジャッジ日時 | 2024-04-20 04:23:48 |
合計ジャッジ時間 | 6,176 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
50,064 KB |
testcase_01 | AC | 48 ms
49,808 KB |
testcase_02 | AC | 48 ms
50,480 KB |
testcase_03 | AC | 48 ms
50,516 KB |
testcase_04 | AC | 48 ms
50,236 KB |
testcase_05 | AC | 48 ms
50,480 KB |
testcase_06 | AC | 49 ms
50,512 KB |
testcase_07 | AC | 48 ms
52,152 KB |
testcase_08 | AC | 49 ms
50,540 KB |
testcase_09 | AC | 48 ms
50,412 KB |
testcase_10 | AC | 50 ms
50,516 KB |
testcase_11 | AC | 53 ms
50,112 KB |
testcase_12 | AC | 49 ms
50,316 KB |
testcase_13 | AC | 50 ms
49,448 KB |
testcase_14 | AC | 52 ms
50,336 KB |
testcase_15 | AC | 50 ms
50,276 KB |
testcase_16 | AC | 53 ms
50,536 KB |
testcase_17 | AC | 52 ms
50,620 KB |
testcase_18 | AC | 50 ms
50,316 KB |
testcase_19 | AC | 52 ms
50,504 KB |
testcase_20 | AC | 81 ms
52,112 KB |
testcase_21 | AC | 79 ms
52,044 KB |
testcase_22 | AC | 58 ms
50,440 KB |
testcase_23 | AC | 73 ms
51,980 KB |
testcase_24 | AC | 56 ms
50,524 KB |
testcase_25 | AC | 72 ms
51,060 KB |
testcase_26 | AC | 84 ms
51,916 KB |
testcase_27 | AC | 64 ms
50,988 KB |
testcase_28 | AC | 62 ms
50,512 KB |
testcase_29 | AC | 86 ms
52,140 KB |
testcase_30 | AC | 90 ms
52,064 KB |
testcase_31 | AC | 81 ms
51,628 KB |
testcase_32 | AC | 65 ms
51,220 KB |
testcase_33 | AC | 78 ms
51,488 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); } } }